How to pass property (SomeProperty) from ParentUserControl context to DependencyProperty (MyDProperty) of the ChildUserControl?
In XAML, it should be: <uc:ChildUserControl MyDProperty="{Binding SomeProperty}"> but, for some reason, MyDProperty never gets set with Parent.DataContext.SomeProperty.
In my case, I'm passing an Action, but that's not important. I think the issue lies in the binding.
ParentUserControl:
public Action RemoveEsl1 => throw new NotImplementedException();
<uc:ChildUserControl Title="ESL 1" RemoveEslAction="{Binding RemoveEsl1}" DataContext="{Binding Esl1}"/>
ChildUserControl:
public static readonly DependencyProperty RemoveEslActionProperty =
DependencyProperty.Register(nameof(RemoveEslAction), typeof(Action), typeof(ChildUserControl), new PropertyMetadata(delegate { }));
public Action RemoveEslAction
{
get => (Action)GetValue(RemoveEslActionProperty);
set => SetValue(RemoveEslActionProperty, value);
}
I found various tips here, but none of them either suited me or worked.
Esl1is actually a property of the current DataContext, and whatDataContext="{Binding Esl1}"is supposed to do whenRemoveEsl1is a property of the parent element. Please provide a minimal reproducible example.RemoveEslAction="{Binding RemoveEsl1, RelativeSource={RelativeSource AncestorType=ParentUserControl}}".