我确实有一个简单的问题,但我似乎找不到它。我正在使用 WPF,并且正在创建一个显示简单 View 的子窗口(类窗口)。现在我可以移动窗口,但我想要的是它不能移动到主窗口之外。 (如果我没记错的话,我认为 Popup 控件具有这种行为)。有什么简单的方法可以做到这一点吗?
如果不清楚,请告诉我。
提前致谢。
亲切的问候, Qwin
最佳答案
使您的父窗口成为子窗口的所有者并调整位置
public MainWindow()
{
InitializeComponent();
LocationChanged += new EventHandler(Window_LocationChanged);
}
ChildWindow win = new ChildWindow();
win.Owner = this;
win.Show();
private void Window_LocationChanged(object sender, EventArgs e)
{
Console.WriteLine("LocationChanged - ({0},{1})", this.Top, this.Left);
foreach (Window win in this.OwnedWindows)
{
win.Top = this.Top + 100;
win.Left = this.Left + 100;
}
}
关于c# - 如何让子窗口限制不超出 WPF 中的主窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30791255/