I am trying to bind to a property while inside a XAML ‘property setter’. Binding at this location does not seem to happen in the same hierarchy as binding at a ‘normal’ place. Does anyone know how to bind something there?
I’ve also tried using RelativeSource to get the parent (which is better, since that’s what I actually want to do, not duplicate it) but no dice.
<loc:MyType Target="{Binding ElementName=Editor, Path=TextArea, Converter={loc:EditorAdapterConverter}}">
<loc:MyType.PopupActions>
<loc:BackspaceHideAction Target="{Binding ElementName=Editor, Path=TextArea, Converter={loc:EditorAdapterConverter}}" /> //Binding doesn't work
<loc:KeyAction Action="Show" Key="Space" Modifiers="LeftCtrl" />
<loc:KeyAction Action="Hide" Key="Escape" />
</loc:MyType.PopupActions>
</loc:MyType>
Relevant information: BackspaceHideAction inherits from FrameworkElement and has a dependency property called Target (actually same as MyType). I need to access this Target also in BackspaceHideAction – it doesn’t really have to be a DP property there as well.
MyType.PopupActions is a dependency property on MyType declared as a PopupActionList : List<PopupAction>.
I am currently assuming that the reason I can’t bind is that I am nested inside a property instantiation. Similar binding have worked elsewhere (just the line above) so the type of binding shouldn’t be the problem. Just the context.
Doing a little further testing, I’ve discovered why it didn’t work.
The dependency property
PopupActionsonMyTypewas declared as aPopupActionList– nothing fancy. But properties aren’t automatically entered into the ‘DOM’-like structure of WPF elements, which isn’t that surprising (after you figure it out, as always).However, with some added code to call
MyType.AddLogicalChildwith each individual PopupAction as the item, everything works fine! (so far)