问题
I am developing a WPF Application for a Shop.
So i have a MainWindow and all the rest will be Child.
Which is the best thing to Use as Child Window.
- Window
- UserControl
Window will be normal, it will be top on the MainWindow and if its UserControl it will be in a Canvas of a MainWindow.
So can anyone suggest me which is best to use out of this two.
回答1:
I would recommend using UserControls for your child windows. This allows you to set up all of the "parent" controls on your main window and the children won't override them.
As a further suggestion, I would recommend looking into Caliburn Micro. That is a great framework for dealing with WPF windows and user controls.
To add a child UserControl to the parent window, I usually just add a ContentControl to my main form like so:
<ContentControl x:Name="ViewWindow" Margin="10" />
Just assign your child to that control and you will be fine.
回答2:
I suggest to use a MDI framework like AvalonDock: http://avalondock.codeplex.com/ You will save a lot of time.
回答3:
Please refer the website : http://wpfmdi.codeplex.com/
回答4:
Like many things in life & coding: it depends :)
Window
- When the new window has its own state & behavior
- When there is little to no interaction/messaging between the main window & the pop-up window
User Control
- When the state of the underlying main window is critical for the operation of the pop-up
- When state changes need to be passed between the 2 windows
These are some of the design decisions which come to mind...
回答5:
Consider to check MDIContainer. A similar project than MDI for WPF, but it gives you more freedom, since it does not force you to implement MDIChild window, interface or anything.
回答6:
Child windows will be great for a desktop application when you are decided to use a parent - child window interaction, although I personally suggest you to use a frame in your main windows and use it to host multiple pages.
To learn more about navigation in WPF and silverlight you can visit this link
Using this approach will help you achieve the following advantages:
- Lesser chance of memory leaks due to unattached event handlers.
- Consistent design could be achieve without indicating style for child windows because you could set page backgrounds to transparent.
- Users wont have a hard time locating which window has the focus when other programs were simultaneously used with the software you are building.
I also think that there are also allot of stuff you could consider in building this software but in the end of the day you are still the one who should decide on this matter.
This is only my suggestion and hope this helps :) .
来源:https://stackoverflow.com/questions/10357567/best-approach-for-a-mdi-application-in-wpf