I agree with all the examples posted here, but I think you are a bit confused due to a completely different “Data” template model in WPF versus the purely closely related WinForms UI + data model.
The transition from WinForm to WPF is a small learning curve, it took me two years to start coding in WPF myself, because I was always more convenient in codebehind files.
My best guess is that first you need to take a look at the WPF concepts with a logical tree and a “Visual tree”, where you will understand how easily WPF UI elements and UI elements (data objects) are connected only in XAML without writing any C #.
And the most important concepts, such as “Triggers”.
All you need to create is the “Data” objects, which will be your chess (King, Horse), etc., obtained from the same base class that implements the IPropertyChanged interface, and they will implement properties such as “CanBeKilled”, "IsPossibleTarget", which may simply be limited to an ItemTemplate ListBox, where your ListBox will contain the current selection.
The ListBox list item panel template can be one of the examples above, and on MouseOver you can select a color or border according to the above properties. And all you have to do is update each element of the boolean properties in the ListBox when the selection changes.
I just read your editing part, and I believe that Code Behind should be different and simple in WPF, because when compared to WinForms, a beautifully designed WPF will have 90% less code compared to WinForm.
Akash Kava
source share