In my WPF project I have a custom control which is visually represented by a rectangle object. In XAML I put a number of rectangles based on this custom control. User should be able to select a group of these rectangles by mouse clicks and then do some actions with these selected rectangles.
How I should implement the possibility of selection: (1) should I simply add yet another custom property e.g. "Selected" and change it in MouseClick event handlers or (2) should I use native 开发者_如何学编程"Logical Focus" functionality?
I'd argue that if you're building selection logic into your control, you may be duplicating functionality already provided by existing Selector
subclasses such as ListBox
.
Why not just host instances of your control inside a ListBox
and let it do the selection logic?
精彩评论