c# WPF Cant get Parent Window
Is the code that you posted in your constructor method?
The parent of a UserControl
is always null in its constructor, so this.Parent
is returning a null reference. Thus, calling Window.GetWindow(this.Parent)
raises an ArgumentNullException
because the dependency object that you specified has not been created yet.
To fix this, you need to place the code in the Initialized
event handler. When this event is raised, you can be sure that the UserControl
has been created.
Try Owner property, you have to assign it.
Sample:
public Activity ShowLookUp(Window owner)
{
ActivityLookUp lookup = new ActivityLookUp();
lookup.Owner = owner;
lookup.ShowDialog();
}