I'm building a BlackJack program and am currently working on the hand display.
I have a PlayerSeat UserControl which has an ItemsControl inside of it for the display of the cards. As with a normal game of BlackJack the cards (images in my case) are laid ontop of one another. Different game actions (Split, Double Down, etc) must change the layouts of the cards on the screen. The ItemsControl's ItemSource property is a "ObservableCollection<Card> Hand" property in my Player's ViewModel. Card objects contains BitmapSources with Card images.
I have looked through several webpages (see end of post) for ways to accomplish what I want. I'm looking for a way to do one of two options.
(Preferable) Specify a layout for each "hand mode" (Split, Double Down, etc) and specify where each index of the Hand (
OC<Card>) should be placed in order. For instance, for the first card in the Hand put a Image control with Source bound to Hand[0].CardImage at (X1, Y1), then put the Hand[1] Image at (X2, Y2), and so on. This would optimally be adjustable by setting some sort of bound template property (to change between the hand modes) on the ItemsControl.(Fallback) Display all the Image controls with their Source properties bound. Have the Top/Left properties of these images bound to Hand[0].Top/Left and do the placement caculations in the Hand class.
I'm not one to ask without investigating the issue myself. It appears I need to use a ItemsPanelTemplate with a StackPanel but have no idea where to begin. The key is making the images overlap and placed where I want them. Any light you could shed on my issue would be helpful.
Reference: http://drwpf.com/blog/itemscontrol-a-to-z/ (Specifically "ItemsControl: 'P' is for Panel")
Could you use a Canvas as the
ItemsPanelTemplate? Something like:This assumes that you have position properties on your
Handclass. If this isn't appropriate, then you could create a wrapperHandViewModelwhich contains theHandinstance, and these additional X,Y properties that are only used for display purposes. The return values for these properties could change based on your current "hand mode".