我需要将上下文菜单与标签绑定,但这段代码对我没用。
<TextBox Width="100" Name="dd" Tag="jatin" Height="50" Text="{Binding Tag, RelativeSource={RelativeSource Self}}">
<TextBox.ContextMenu>
<ContextMenu>
<MenuItem Header="harsh"></MenuItem>
<MenuItem Header="jatin"></MenuItem>
<MenuItem Header="{Binding Path=Tag,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Grid},FallbackValue=BindingFailed}"></MenuItem>
</ContextMenu>
</TextBox.ContextMenu>
</TextBox>
</Grid>
试试这个,
<MenuItem Header="{Binding Path=PlacementTarget.Tag, RelativeSource={RelativeSource AncestorType=ContextMenu}}" />