我正在使用WPF Popup控件.我希望它出现在我的应用程序窗口中,锚定在窗口的右下角.弹出窗口的实际高度和宽度将根据显示的消息而改变.
如果重要,弹出窗口的内容是一个Border,包装StackPanel,持有多个TextBlocks.
感谢您的任何帮助.
我刚刚做了类似的事情,它确实没有那么棘手,但它确实需要自定义弹出窗口的位置。声明弹出窗口时,只需将 PlacementMode 属性设置为 Custom,然后将 CustomPopupPlacementCallback 属性设置为您要使用的方法。
this.trayPopup.CustomPopupPlacementCallback = GetPopupPlacement;
private static CustomPopupPlacement[] GetPopupPlacement(Size popupSize, Size targetSize, Point offset)
{
var point = SystemParameters.WorkArea.BottomRight;
point.Y = point.Y - popupSize.Height;
return new[] { new CustomPopupPlacement(point, PopupPrimaryAxis.Horizontal) };
}
Run Code Online (Sandbox Code Playgroud)
小智 5
使用PlacementTarget,Placement = Left,Horizontal / VerticalOffset
<Popup IsOpen="{Binding ElementName=togglebutton, Path=IsChecked, Mode=TwoWay}"
PlacementTarget="{Binding ElementName=togglebutton}"
Placement="Left"
HorizontalOffset="{Binding ActualWidth, ElementName=togglebutton}"
VerticalOffset="{Binding ActualHeight, ElementName=togglebutton}">
Run Code Online (Sandbox Code Playgroud)
这是相当棘手的,并且没有简单的答案。关于你的问题,你说:
弹出窗口的实际高度和宽度将根据正在显示的消息而变化。
您应该不用担心,这是 WPF Popup 控件的默认行为。
确保您想要担任的职位的步骤是:
有关使用 Popup 的自定义放置的更多信息,请参阅: