Reputation: 183
I would like to know if any way to "mark" a group of controls in WPF and then retrive those controls in a window.xaml.cs
function.
Due the layout of the window the controls cannot be grouped under any xaml structure.
I would like something like this
<Button Selection="selection" />
<Textbox />
<Label Selection="selection" />
-
function someEvent()
{
//In here get a collection with the button and the Label using 'selection'
}
The important thing is that the identifier cannot be unique, I can't use Name
and also must not be generic, I cant use Label
or Button
.
And finally as I said at the beggining, controls cannot be encolsed in any kind of group either. They may be encolsed separately.
Thank you all!
Upvotes: 0
Views: 77
Reputation: 7421
As per my comment, WPF controls have a Tag
property that can be used to add arbitrary information to a control. That said, a better solution is to implement an Attached Property that has both the correct type, and encapsulates the intent of your 'mark'.
From an 'XY problem' perspective, there is likely a more basic requirement that has led you to this specific question. Since you didn't include further details, all I can add is that there is likely a better way to handle things like enabling/disabling a set of controls, or even using an ItemsControl with a DataTemplate to treat the 'group' as a single entity. I recommend including scenario details in your SO questions.
Upvotes: 2