Answer the question
In order to leave comments, you need to log in
How to forward a property from a WPF control?
I have this property in my control
public ObservableCollection<object> Items
{
get => (ObservableCollection<object>)GetValue(ItemsProperty);
set
{
SetValue(ItemsProperty, value);
}
}
public static readonly DependencyProperty ItemsProperty;
static FilteredListBox()
{
ItemsProperty = DependencyProperty.Register("Items",
typeof(ObservableCollection<object>),
typeof(FilteredListBox),
new FrameworkPropertyMetadata(new ObservableCollection<object>(),
FrameworkPropertyMetadataOptions
.AffectsMeasure
| FrameworkPropertyMetadataOptions
.AffectsRender,
new PropertyChangedCallback(OnItemsChanged)));
}
<ListBox Name="_listBox"
ItemsSource="{Binding Items}"
/>
<ctrls:MyListBox Items="{Binding Departments}"/>
Answer the question
In order to leave comments, you need to log in
Try to specify the binding in the UserControl itself in the ListBox like this:
<ListBox Name="_listBox"
ItemsSource="{Binding Items, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
/>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question