我需要将上下文菜单与标签绑定,但这段代码对我没用

问题描述 投票:0回答:1

我需要将上下文菜单与标签绑定,但这段代码对我没用。

    <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>
wpf xaml
1个回答
0
投票

试试这个,

<MenuItem Header="{Binding Path=PlacementTarget.Tag, RelativeSource={RelativeSource AncestorType=ContextMenu}}" />
© www.soinside.com 2019 - 2024. All rights reserved.