Binding Error 4 RelativeSource FindAncestor BindingExpression:Path=Parent
Genteure opened this issue · 1 comments
Genteure commented
Problem
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.FrameworkElement', AncestorLevel='1''. BindingExpression:Path=Parent; DataItem=null; target element is 'ContextMenu' (Name=''); target property is 'Parent' (type 'DependencyObject')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.FrameworkElement', AncestorLevel='1''. BindingExpression:Path=Parent; DataItem=null; target element is 'StackPanel' (Name=''); target property is 'Parent' (type 'DependencyObject')
I'm using ContextMenu in Resources
<UserControl
...
xmlns:lex="https://github.com/XAMLMarkupExtensions/WPFLocalizationExtension"
lex:LocalizeDictionary.DesignCulture=""
lex:ResxLocalizationProvider.DefaultAssembly="MyAssembly"
lex:ResxLocalizationProvider.DefaultDictionary="Resources"
>
<UserControl.Resources>
<ContextMenu x:Key="ContextMenuResourcesKey">
<MenuItem Header="{lex:Loc MenuItemKey}"/>
</ContextMenu>
</UserControl.Resources>
...
</UserControl>
I believe this is a duplicate of #55 #96 #144 #152
Workaround
Add lex:ResxLocalizationProvider.DefaultDictionary="Resources"
to the element in question so it looks like
<UserControl
...
xmlns:lex="https://github.com/XAMLMarkupExtensions/WPFLocalizationExtension"
lex:LocalizeDictionary.DesignCulture=""
lex:ResxLocalizationProvider.DefaultAssembly="MyAssembly"
lex:ResxLocalizationProvider.DefaultDictionary="Resources"
>
<UserControl.Resources>
<ContextMenu x:Key="ContextMenuResourcesKey"
lex:ResxLocalizationProvider.DefaultDictionary="Resources">
<MenuItem Header="{lex:Loc MenuItemKey}"/>
</ContextMenu>
</UserControl.Resources>
...
</UserControl>
ref: #55 (comment)
GF-Huang commented
So you should put lex:ResxLocalizationProvider.DefaultDictionary="Resources"
everywhere you use a ContextMenu
.. 😢