c# - Having Trouble Setting Window's Owner in Parent's Constructor -
is there wrong in wpf setting owner property of window parent in parent's constructor? there shouldn't be, right? why getting xamlparseexception
following code?
public partial class mainview : window { private readonly ownedwindow owned; public mainview() { initializecomponent(); owned = new ownedwindow(); owned.datacontext = datacontext; var window = getwindow(this); owned.owner = this; //setting window causes same error ... }
i should clarify removing owned.owner = this;
removes runtime error.
the details of exception:
xamlparseexception unhandled
the invocation of constructor on type '...mainview' matches specified binding constraints threw exception.
actually, looked @ inner exception, , says:
cannot set owner property window has not been shown previously.
so i'm looking now.
the problem because wpf creates native window first time wpf window shown, can't setting not-yet-shown window owner
(since establishes native window "owner -> owned" relationship, native handle doesn't yet exist.)
you can handle statechanged
event on owner window, ensure new state "shown", , set owned window's owner
@ point. alternatively, create , show owned window @ point.
Comments
Post a Comment