关于如何移动这个职位的任何想法?这是菜单:
这是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>
答案 0 :(得分:4)
从MSDN开始,您可以使用Placement=Relative
模式:
Popup控件相对于PlacementTarget左上角的位置,以及由HorizontalOffset和VerticalOffset属性值定义的偏移量。如果屏幕边缘遮挡了弹出窗口,则控件会重新定位以与屏幕边缘对齐。
换句话说,你可以这样做:
<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}">
请注意使用负值HorizontalOffset
和VerticalOffset
答案 1 :(得分:-1)
来自按钮点击的活动
private void button_Click(object sender, RoutedEventArgs e)
{
Button button = sender as Button;
popup.PlacementTarget = button;
popup.HorizontalOffset = -120;
popup.VerticalOffset = -130;
popup.IsOpen = true;
}