Reputation: 10203
I'm developing a WPF application where I would like a common toolbar along the top of the screen (when I say "toolbar" it won't be a WPF ToolBar control, more likely just a series of image buttons resembling a Windows 8 app bar). I'm using Prism navigation.
What I had in mind was that this toolbar would live in the main window, and always be visible throughout the application. The toolbar would include a couple of standard buttons such as "Exit" and "Help".
Below the toolbar, the main window essentially just contains a large Prism region. When I navigate this region to a view (call it "view1") I want view1 to add additional buttons into the toolbar.
Now, "view1" may have Prism regions of its own, and when one of these is navigated to a view (call it "view2"), view2 should be able to add buttons of its own, alongside the "standard" main window buttons and the buttons added by view1.
It goes without saying that the relevant buttons should be removed when navigating away from a view.
I'm sure I could roll my own solution, but wondered if I could simplify things with Prism? I thought about putting a Prism region in the toolbar alongside the "standard" buttons. "view1" would then navigate this region to a view that basically just contains view1's buttons. This "view1 button view" could itself contain a region, that view2 could navigate to its own "button view". Is this viable, or is it going to get too complicated?
Upvotes: 1
Views: 529
Reputation: 2935
It sounds like you might be complicating it a bit, or at least you lost me at the end...but that doesn't take much today!
A suggestion: Your "toolbar" could be, for example, some ItemsControl
where your ItemsSource
is a collection of some class ToolBarOperation
. This class could contain a description to display to the user and an ICommand to perform when clicked. Style your ItemsControl
's items to be buttons and bind each button's command to your class's ICommand. This collection would be populated by the currently visible view's viewmodel (i.e. View1
's viewmodel would already know what commands it would be responsible to perform. When View1
is loaded, fill the collection with ViewModel1
's list of ToolBarOperation
.)
So, to answer your question, I don't think you need anything Prism specific (except maybe their implementation of DelegateCommand
)...the "Controller pattern" discussed in the documentation might be helpful. But it shouldn't be hard to accomplish what you want with Prism alongside.
Upvotes: 0