Reputation: 5134
I noticed that if I move my WPF window through code, I will only see that changes when the window refreshes (if I minimize and then maximize it).
Is it possible to refresh the GUI of a WPF on demand?
EDIT: I'm actually trying to make this window follow another window.
So I'm hooking to the other window's events:
m_wndParent = parent;
this.Owner = m_wndParent;
m_wndParent.SizeChanged += ParentSizeChanged;
m_wndParent.LayoutUpdated += ParentLocationChanged;
and then I change my window's position:
private void ParentLocationChanged(object sender, EventArgs e)
{
Window parent = sender as Window;
this.Top = parent.Top;
this.Left = parent.Left;
this.UpdateLayout();
}
Upvotes: 2
Views: 23652
Reputation: 5764
You should hook up parent.LocationChanged and then call InvalidateVisual. See MSDN for more details.
Upvotes: 0
Reputation: 128157
You should add your ParentLocationChanged
handler to the LocationChanged event instead of LayoutUpdated (which serves a completely different purpose).
m_wndParent.LocationChanged += ParentLocationChanged;
private void ParentLocationChanged(object sender, EventArgs e)
{
var parent = sender as Window;
Top = parent.Top;
Left = parent.Left;
}
Upvotes: 1