我有一个ToggleButton,点击后,将IsActionMenuOpen
设置为true,以便显示弹出窗口。我期望的结果是弹出窗口的位置会像here一样位于右下角。关于如何做到这一点的任何想法?此外,如果正在调整窗口大小,是否可以找到解决方案以便弹出窗口也会移动?
<ToggleButton x:Name="PART_TGAction">
<ToggleButton.Template>
<ControlTemplate>
<TextBlock x:Name="PART_SubjectActions"
Text="Actions"
Margin="4,0,0,0"
PreviewMouseLeftButtonDown="PART_SubjectActions_PreviewMouseLeftButtonDown"
/>
</ControlTemplate>
</ToggleButton.Template>
</ToggleButton>
<Popup IsOpen="{Binding IsActionMenuOpen, Mode=OneWay}"
x:Name="PART_Popup">
<Border Background="White">
......
</Border>
</Popup>
答案 0 :(得分:1)
我可以通过将它放在UserControl的Loaded事件中来实现这一点:
PART_Popup.CustomPopupPlacementCallback += (Size popupSize, Size targetSize, Point offset) => new[] { new CustomPopupPlacement() { Point = new Point(targetSize.Width - popupSize.Width, targetSize.Height) } };