Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF绑定从ContextMenu选择EdItem到Button.Content_Wpf_Xaml_Button_Binding_Contextmenu - Fatal编程技术网

WPF绑定从ContextMenu选择EdItem到Button.Content

WPF绑定从ContextMenu选择EdItem到Button.Content,wpf,xaml,button,binding,contextmenu,Wpf,Xaml,Button,Binding,Contextmenu,我在XAML中的按钮上有一个上下文菜单。ContextMenu项由ItemsSource属性加载。现在我想用ContextMenu的SelectedItem.text设置按钮的文本。有什么解决办法吗 以下是我的XAML代码片段: <Button Grid.Column="4" Grid.Row="1" Width="100" Height="24" BorderThickness="0" Command="{Binding SwitchFieldClickCommand}" Content

我在XAML中的按钮上有一个上下文菜单。ContextMenu项由ItemsSource属性加载。现在我想用ContextMenu的SelectedItem.text设置按钮的文本。有什么解决办法吗

以下是我的XAML代码片段:

<Button Grid.Column="4" Grid.Row="1" Width="100" Height="24" BorderThickness="0" Command="{Binding SwitchFieldClickCommand}" Content="{}">
        <Button.ContextMenu>
            <ContextMenu Name="CM_SwitchField">
                <ItemsControl ItemsSource="{Binding Benutzer.SwitchFieldList}" />                
            </ContextMenu>
        </Button.ContextMenu>
</Button>

我在按钮的content属性中尝试过:content={Binding RelativeSource={RelativeSource Mode=Self},Path=Items[0]。SelectedItem.Text}Items控件的XAML可能不起作用。上下文菜单与应用程序的其余部分不属于同一个VisualTree,因此绑定的工作方式与您期望的不同。您可以使用ContextMenu的PlacementTarget来获取对主VisualTree的引用,就像任何人都可以给我举一个例子说明我的情况一样,因为我不明白如何将所选项目从上下文菜单放入按钮的文本中