Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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中向菜单项添加矩形?_Wpf_Xaml - Fatal编程技术网

如何在WPF中向菜单项添加矩形?

如何在WPF中向菜单项添加矩形?,wpf,xaml,Wpf,Xaml,我正在用矩形自定义菜单项。我需要删除默认菜单项中的所有特征,并将自定义矩形添加到菜单中。我不确定菜单项的哪个属性应该被覆盖?有什么帮助吗?定义如下模板: <ControlTemplate x:Key="customMenuItem" TargetType="{x:Type MenuItem}"> <WrapPanel Background="Gray" Margin="3"> <Rectangle Fill="Blac

我正在用矩形自定义菜单项。我需要删除默认菜单项中的所有特征,并将自定义矩形添加到菜单中。我不确定菜单项的哪个属性应该被覆盖?有什么帮助吗?

定义如下模板:

    <ControlTemplate x:Key="customMenuItem" TargetType="{x:Type MenuItem}">
        <WrapPanel Background="Gray" Margin="3">
            <Rectangle Fill="Black" Width="16"/>
            <ContentPresenter Content="{TemplateBinding Header}"/>
        </WrapPanel>
    </ControlTemplate>

然后将其用作任何菜单项的模板

<Menu>
    <MenuItem Template="{StaticResource customMenuItem}" Header="some text"/>
</Menu>