I have a problem with binding ContextMenu Tag to Owner Tag. I trying like this:
<Style x:Key="DefaultTextBox" TargetType="{x:Type TextBox}">
<Setter Property="BorderBrush" Value="{DynamicResource ThemeSecondary}"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="Tag" Value="{Binding RelativeSource={RelativeSource Mode=Self}}"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu x:Name="uiContexMenu">
<ContextMenu.ItemsSource>
<CompositeCollection>
<MenuItem Command="Cut" Header="Cut">
<MenuItem.Icon>
<Viewbox Width="16" Height="16">
<TextBlock FontFamily="{DynamicResource IconFont}" Text=""/>
</Viewbox>
</MenuItem.Icon>
</MenuItem>
<MenuItem Command="Copy" Header="Copy">
<MenuItem.Icon>
<Viewbox Width="16" Height="16">
<TextBlock FontFamily="{DynamicResource IconFont}" Text=""/>
</Viewbox>
</MenuItem.Icon>
</MenuItem>
<MenuItem Command="Paste" Header="Paste">
<MenuItem.Icon>
<Viewbox Width="16" Height="16">
<TextBlock FontFamily="{DynamicResource IconFont}" Text=""/>
</Viewbox>
</MenuItem.Icon>
</MenuItem>
<CollectionContainer Collection="{Binding ElementName=uiContexMenu, Path=Tag(local:Extensions.ExtendCommands)}"/>
</CompositeCollection>
</ContextMenu.ItemsSource>
</ContextMenu>
</Setter.Value>
</Setter>
If check with Snoop (xaml debuger) binding show error:
System.Windows.Data.Error: 4: Cannot find source for binding with reference 'RealativeSource FindAncestor, AncestorType='System.Windows.Controls.TextBox', AncestorLevel='1''. BindingExpression: Path=Tag; DataItem=null; target element is 'ContextMenu'(Name='uiContextMenu'); target property is 'Tag' (type 'Object')
Can someone help? Thanks
Path=Tag(local:Extensions.ExtendCommands)
. – AnjumSKhan