omniplex

Archive for July, 2010

WPF and new Windows.

by on Jul.14, 2010, under Personal, Random

So I’m learning to program a GUI with WPF and most of the examples that I have seen don’t include alot of real navigation unless you are using a Page and treating it more like a browser page.  However I have been trying to use “Windows” with “Grid” containers to do Navigation similar to how Windows Media Center does it’s navigation.  Since I’m still learning WPF  I don’t know all the ins and outs yet. However, I did find this little tidbit.

If I have a main Window with a grid container I can clear the contents of the container and load it with the contents of another xaml file as a child.  However, what I found was that I could not reload the original window contents without very well. One of the primary reasons is that I need to detach the new window and then close it. I can detach the window by assigning the Content to null. Then I would call the .Close() method to close it out. If I do not do this, when I terminate the application it leaves the GUI thread hanging and doesn’t actually close out the process.

Here is the sample code:

AdminWindow myAdmin = new AdminWindow();
 object content = myAdmin.Content;
 myAdmin.Content = null;
 myAdmin.Close();
 _Grid.Children.Clear();
 _Grid.Children.Add(content as UIElement);

Hopefully that makes sense to everyone. I’m still working on my writing and trying to get information out.

Leave a Comment more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!