我正在创建自己的AboutBox,并使用Window.ShowDialog()调用它。
我如何让它相对于主窗口的位置,即从顶部到居中的20px?
发布于 2015-12-02 17:47:29
我会用手工的方式,而不是依靠WPF来为我计算。
System.Windows.Point positionFromScreen = this.ABC.PointToScreen(new System.Windows.Point(0, 0));
PresentationSource source = PresentationSource.FromVisual(this);
System.Windows.Point targetPoints = source.CompositionTarget.TransformFromDevice.Transform(positionFromScreen);
AboutBox.Top = targetPoints.Y - this.ABC.ActualHeight + 15;
AboutBox.Left = targetPoints.X - 55;
其中ABC
是父窗口中的某个UIElement (如果您喜欢,可以是所有者),也可以是窗口本身(左上角)..
祝好运
https://stackoverflow.com/questions/2446602
复制相似问题