Reputation: 123
I have a simple problem in WPF/C#. I want to drag and drop some images into a layout and adjust their sizes according to the number of images (it can be more than 2!).
I have no problem with the Drag&Drop system. My problem is about the resizing elements/splitting the layout. I tried several things such as using ItemsControl
with a WrapPanel
but it is not working. I just see the image 1 in full size.
ItemsControl
with a WrapPanel
a good way ? Here my XAML
<ItemsControl x:Name="list" AllowDrop="True"
Drop="list_Drop" Background="Transparent" Grid.IsSharedSizeScope="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled" BorderBrush="{x:Null}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel ScrollViewer.VerticalScrollBarVisibility="Disabled" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
And here my code-behind
private void list_Drop(object sender, DragEventArgs e)
{
Thumbnail thumbnail = sender as Thumbnail;
Image addedImg = new Image();
addedImg.Source = (BitmapImage)e.Data.GetData(typeof(BitmapImage));
list.Items.Add(addedImg);
this.UpdateLayout();
}
Thank you !
Upvotes: 2
Views: 354
Reputation: 6690
ItemsControl with the ItemsPanel set to UniformGrid.
<ItemsControl ItemsSource="{Binding ImagesList}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid/>
</ItemsPanelTemplate>
<ItemsControl.ItemsPanel>
</ItemsControl>
Upvotes: 2