sorry to bug you with a beginner question. I am trying to achieve an Image Grid (like in a comic viewer or a movie database) with WPF in C#.
Now I tried to use ListView and ListBox initially but I did not get it working to have a simple styled image grid. Then I stumbled upon an ItemsControl in combination with a WrapPanel. This worked out fine easily.
Then I tried to implement a method that opens the clicked image and I got stuck. Now I found in various articles that ItemsControl does not supply actions to read the currently selected item index.
Now I am a bit disillusioned how to go on. Do you have an example code for a simple ImageGrid or an Idea to use the ItemsControl anyway? The only idea I had was to read the Image source of the sender object and then compare it with a list of images.
Here is my XAML code:
<ItemsControl Name="ImageHistory" Margin="100" HorizontalAlignment="Center" HorizontalContentAlignment="Center">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Margin="15" MouseUp="OpenDirectory" MouseEnter="HighlightButton" MouseLeave="UnhighlightButton">
<Image Source="{Binding ImageData}" Height="150" Width="150" Margin="10"
RenderOptions.BitmapScalingMode="HighQuality" Stretch="UniformToFill"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
Thanks a lot in advance!!
Ok, I did it. It was quite simple as soon as I asked the right question. Removing the scroll functionality did the trick. Here is the working code:
Thanks a lot anyway :)