我在DataTemplate里面有一个弹出窗口,我想要的是居中对齐弹出窗口。屏幕尺寸。下面是我用于使弹出窗口居中的代码,但是这种情况是我在网格内有三行,而ListView在第二行中,这是因为弹出窗口无法容纳屏幕中心。另外,我不能将其移出DateTemplate,因为它需要该项的单独DataContext。
private void Popup_SizeChanged(object sender, SizeChangedEventArgs e)
{
var popup = sender as Popup;
CoreWindow yourContainingWindow = Window.Current.CoreWindow;
Rect windowBounds = yourContainingWindow.Bounds;
Point windowCenter = new Point(windowBounds.Left + (windowBounds.Width / 2.0), (windowBounds.Height / 2.0));
popup.SetValue(Popup.HorizontalOffsetProperty, windowCenter.X - (popup.ActualWidth / 2.0));
popup.SetValue(Popup.VerticalOffsetProperty, -(popup.ActualHeight / 2.0));
}
关于如何实现上述输出的任何建议?