Reputation: 7208
What's the elegant way of exposing ItemContainerGenerator
from custom control?
I have ItemsSource
property on my custom control and I would like to access UIElement
corresponding to the bound item outside of it.
I don't have access to the ItemsControl
nor ItemsContainerGenerator
outside of my control. Should I expose ItemsControl
or ItemContainerGenerator
as a property, or maybe add a method for retrieving the UIElement
?
I need to show the popup near the selected item. Maybe the popup should be a part of the control then I wouldn't have to do this?
Upvotes: 0
Views: 197
Reputation: 169200
If you want to be able to access the entire child ItemsControl
, create a public read-only property that returns it.
If you only want to expose the ItemContainerGenerator
, create a read-only property that returns it, e.g.:
public ChildItemContainerGenerator => childControl.ItemContainerGenerator;
If it makes no sense to expose the entire ItemContainerGenerator
, create a public method that uses the ItemContainerGenerator
internally to perform whatever you want to.
Which option to choose all comes down to your requirements actually.
Upvotes: 1