How do you use a child window in Silverlight such that it is not done asynchronous?
How do you use a child window in Silverlight such that it is not done asynchronous? The way you use a child window in Silverlight (so far as I know) is to use the show method:
ChildWindow update_dlg = new Upd开发者_Go百科ate();
update_dlg.Show();
But you cannot get the input from the dialog because the call is asynchronous and keeps on running while the child window us up.
You can't, you need to listen for the child window closing then grab the dialog result.
From MSDN page:
To get the DialogResult value from a child window, handle the Closed event in the code-behind page of the calling window. In the Closed event handler, cast the sender parameter to a ChildWindow or a derived class to access the DialogResult property.
I like to pass an Action to the child window, if the user cancels the window nothing is called, if the user accepts the window the action is executed with the parameters from the window. This way the code to run when the user accepts is still written in the calling window.
There are three ways of doing this as I see it.
1) launch a seperate thread in the main app that waits until some third party class member is switched from true to false to indicate that the child window has been closed. Then in the child window, when a shutdown or OK or Cancel is done, this third party class member is switched too false etc. (this is the way i did this)
2) have a call back function in the main program that is called by the child window.
3) kind of cheat and don't have a child window at all. Instead, in the XAML code of the main window, have a rectangle that looks like a pop up or child window that is hidden (visual set to collapse) that comes up (but really becomes visual) and all other fields in the main program are set to inactive until the right butons are puched.**
精彩评论