2

我注意到如果我通过代码移动我的 WPF 窗口,我只会在窗口刷新时看到变化(如果我最小化然后最大化它)。
是否可以按需刷新 WPF 的 GUI?

编辑:我实际上是想让这个窗口跟随另一个窗口。

所以我挂钩到另一个窗口的事件:

    m_wndParent = parent;
    this.Owner = m_wndParent;
    m_wndParent.SizeChanged += ParentSizeChanged;
    m_wndParent.LayoutUpdated += ParentLocationChanged;

然后我改变我的窗口的位置:

   private void ParentLocationChanged(object sender, EventArgs e)
        {
            Window parent = sender as Window;
            this.Top = parent.Top;
            this.Left = parent.Left;
            this.UpdateLayout();
        }
4

2 回答 2

1

您应该将ParentLocationChanged处理程序添加到LocationChanged事件而不是LayoutUpdated(其用途完全不同)。

m_wndParent.LocationChanged += ParentLocationChanged;

private void ParentLocationChanged(object sender, EventArgs e)
{
    var parent = sender as Window;
    Top = parent.Top;
    Left = parent.Left;
}
于 2013-01-06T15:01:23.263 回答
0

您应该连接 parent.LocationChanged,然后调用 InvalidateVisual。有关详细信息,请参阅MSDN 。

于 2013-01-06T15:07:44.193 回答