Depending on the number of selected pictures, you need to generate a certain number of pictures on the page. What I do: I throw pictures to the list, then I read alternately and throw to another list.
ViewModel

 private IReadOnlyList<StorageFile> collageimages; private List<CollageModel> imageList; private Thickness temp = new Thickness (50, 50, 0, 0); public ImageManipulatorViewModel() { this.ImageList = new List<CollageModel>(); } public List<CollageModel> ImageList { get { return this.imageList; } set { this.imageList = value; base.RaisePropertyChanged("ImageList"); } } this.collageimages = await OpenPicker.PickMultipleFilesAsync(); for (var i = 0; i < collageimages.Count-1; i++) { var stream = await collageimages[i].OpenAsync(FileAccessMode.Read); var bitmapImage = new WriteableBitmap(100, 100); bitmapImage.SetSource(stream); this.ImageList.Add(new CollageModel() {CollageImage = bitmapImage, Margins = this.temp}); } 

Model :

 public class CollageModel { public Thickness Margins { get; set; } public WriteableBitmap CollageImage { get; set; } } 

Binding on Xaml :

  <UserControl.DataContext> <StaticResource ResourceKey="ImageManipulatorViewModel"/> </UserControl.DataContext> <!--...--> <Canvas Width="Auto" Height="1200" x:Name="MyCanvas" Margin="0,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Center"> <ItemsControl ItemsSource="{Binding ImageList}"> <ItemsControl.ItemTemplate> <DataTemplate x:DataType="models:CollageModel"> <Image Source="{x:Bind CollageImage}" Margin="{x:Bind Margins}" Height="100" Width="100"> </Image> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> 

But as a result there is nothing on the form. On debug, it enters the method normally, fills the list

  • And the DataContext installed? - Donil
  • @Donil, yes, updated the question - SmiLe

1 answer 1

Instead of List<CollageModel> try ObservableCollection<CollageModel>

  • It helped, just why the pictures appear in the column? Margin static, in theory they should be on top of each other - SmiLe
  • I think, here it is necessary to climb in ItemContainerStyle . - Make Makeluv
  • A little google, all examples for lists and for WPF, maybe there is some kind of list of styles? Property window doesn’t tell anything either - SmiLe
  • All standard styles lie here c:\Program Files (x86)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\10.0.14393.0\Generic\generic.xaml Copy to yourself any resources, change as you like and use. - Make Makeluv