c# - 我可以更改弹出窗口的对齐方式,使其出现在按钮的左侧而不是右侧吗?

标签 c# wpf xaml popup togglebutton

关于如何移动位置的任何想法?这是菜单:

enter image description here

这是 XAML:

<Canvas MinHeight="25" Panel.ZIndex="99">
<ToggleButton x:Name="btnPluginMenu" Content="CT" Width="48" Height="48" Canvas.Left="452" Canvas.Top="263"/>
<Popup Placement="Top" PlacementTarget="{Binding ElementName=btnPluginMenu}" IsOpen="{Binding ElementName=btnPluginMenu, Path=IsChecked}">
<Grid Background="Gray" Width="175" Height="130">
                    <Grid.BitmapEffect>
                        <DropShadowBitmapEffect />
                    </Grid.BitmapEffect>
 </Grid>
            </Popup>
</Canvas>

最佳答案

来自 MSDN您可以使用 Placement=Relative 模式:

A position of the Popup control relative to the upper-left corner of the PlacementTarget and at an offset that is defined by the HorizontalOffset and VerticalOffset property values. If the screen edge obscures the Popup, the control repositions itself to align with the screen edge.

换句话说,你可以这样做:

<ToggleButton x:Name="btnPluginMenu" Content="CT" Width="48" Height="48" Canvas.Left="452" Canvas.Top="263"/>
<Popup Placement="Relative"  HorizontalOffset="-120" VerticalOffset="-130" PlacementTarget="{Binding ElementName=btnPluginMenu}" IsOpen="{Binding ElementName=btnPluginMenu, Path=IsChecked}">

注意负值 Horizo​​ntalOffsetVerticalOffset 的用法

关于c# - 我可以更改弹出窗口的对齐方式,使其出现在按钮的左侧而不是右侧吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14267986/

相关文章:

WPF Datagrid 行颜色基于值

c# - 没有服务定位器的 IFilterProvider 注入(inject)

c# - WPF 通过操作调整矩形大小不保持比例

c# - C#或者底层的CLR真的不支持多重继承吗?

wpf - (临时)在 WPF 中禁用验证

wpf - 停止从一个用户控件跳出到另一个用户控件的键盘方向导航

wpf - 列出WPF特定窗口的所有控件

wpf - 无法编辑我的 DataGrid WPF Framework 4.5 的单元格

C# - 标记自定义窗体的基类使设计 View 显示 HTML

c# - 属性、索引器或动态成员访问不能作为具有只读属性的 out 或 ref 参数传递