I was wondering what the best approach is for sharing a menu across all wpf windows/views.
My Application doesnt really fit the navigation model, so will probably use a Ribbon control.
I am leaning towards creating a user control for the menu and dropping开发者_Go百科 it on each view, but have also seen Josh Smith's msdn article, where he loads user controls.
Are there any other options or established best practices?
Thanks in Advance.
I ended up implementing in a way similar to Josh Smiths; I have however simplified things a bit.
All views are usercontrols, except the MainWindow. The MainWindow contains a ContentTemplate which is bound to a property holding reference to a single UserControl in the view model. I then have an ApplicationController responsible for controlling the view and view model lifecycle. The ViewModel base class used by each view contains a reference to the IApplicationController. The MainWindowViewModel then makes calls to the ApplicationController to load a new view etc.
Still not 100% on this approach so would welcome any further suggestions.
Here's what I would probably try:
- Define an
ISharedMenu
interface - Create a UserControl which uses the
ISharedMenu
as its DataContext. - For each ViewModel that you want to use the shared menu, implement the
ISharedMenu
interface.
精彩评论