I need to display a cards game board. My BoardViewModelM exposes an IEnumerable where the CardViewModel has the information where the card should be drawn on the board. I would like the baord to:
I was considering:
What should be my course of action?
I would use binding to display your card collection - one option is to use an ItemsControl
with a Canvas
as the ItemsPanel
, and set the ItemContainerStyle
to position each card. Something like:
<ItemsControl ItemsSource="{Binding CardCollection}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Source="{Binding CardImage}" Width="{Binding CardWidth}" Height="{Binding CardHeight}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Canvas.Left" Value="{Binding CardX}" />
<Setter Property="Canvas.Top" Value="{Binding CardY}" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>