设置在XAML一个WPF文本菜单的PlacementTarget财产? [英] Setting a WPF ContextMenu's PlacementTarget property in XAML?

查看:1077
本文介绍了设置在XAML一个WPF文本菜单的PlacementTarget财产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<Button Name="btnFoo" Content="Foo" >
    <Button.ContextMenu Placement="Bottom" PlacementTarget="btnFoo">
        <MenuItem Header="Bar" />
    </Button.ContextMenu>
</Button>

给我一个运行时错误的UIElement类型不具有公共的TypeConverter类

gives me a runtime error 'UIElement' type does not have a public TypeConverter class

我也试过

<Button Name="btnFoo" Content="Foo" >
    <Button.ContextMenu Placement="Bottom" PlacementTarget="{Binding ElementName=btnFoo}">
        <MenuItem Header="Bar" />
    </Button.ContextMenu>
</Button>

和该把文本菜单中我的屏幕的左上角,而不是在按钮

and that put the ContextMenu in the top left corner of my screen, rather than at the Button

推荐答案

您应该设置按钮上的ContextMenuService.Placement附加属性,如言论的文档中的<一说href=\"http://msdn.microsoft.com/en-us/library/system.windows.controls.contextmenu.placement.aspx\">ContextMenu.Placement.

You should be setting the ContextMenuService.Placement attached property on the button, as stated in the remarks in the documentation for ContextMenu.Placement.

<Button Name="btnFoo" Content="Foo" ContextMenuService.Placement="Bottom">
    <Button.ContextMenu>
        <ContextMenu>
            <MenuItem Header="Bar" />
        </ContextMenu>
    </Button.ContextMenu>
</Button>

这篇关于设置在XAML一个WPF文本菜单的PlacementTarget财产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆