Hi Everyone,
I have a UserControl (extended as MyControl) which displays a list of views (UserControls).
The child controls expanders and I want to control them from the parent window.
(More on the code and design over here)
I have given this in the child UserControls:
IsExpanded="{Binding Path=ExpanderProperty.IsChecked, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MyControl}, AncestorLevel=2} ,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
AncestorLevel set as 2 as this control itself is of type MyControl, and I want to find the ExpanderProperty in the parent control, which is defined like this in the parent control :
public ToggleButton ExpanderProperty
{
get{ return myToggleButton; }
}
But this doesn't work.
I have tried pretty much all combinations here but no use.
One interesting thing I found was the child controls are created first, this I confirmed through the constructor in MyControl, and the parent control created at last (this happens due to the design, the views are created to build an ObservableCollection etc).
So the question came to my mind: Is the binding not working because when the child control is created, the parent doesn't exist! and is crated later?
Is that possible?
I can see that once they are all up and running the Visual tree looks fine (checked through WPF Inspector tool) but binding doesn't work.
Can I somehow re-enforce the binding once the parent is ready?
I am not sure that even makes sense but I am all out of options here.
Thank you.
Please Mark as Answered If this answers your question OrUnMark as Answered if it did not.
Happy to Help :)
My Site