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?
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.
Related
I'm on writing a simple application, it has a menu and when user choices each MenuItem, i want to change my window's content to display the selected content.
i have two option to that.
i can add a <Frame></Frame> to my window and write some pages.
i can write some UserControls and put them in a ContentControl
as user fires MenuItem click event.
so I'm confused to select the right choice for this purpose.
Navigation can be succefully implemented by using Frame/Pages or ContentControl/Views. It is a matter of choice.
However, Frame/Page have some gotchas, e.g. page.DataContext not inherited from parent Frame?
If you don't need isolation specifically, then stick to ContentControl. Navigation in prism framework is built with regions which are located in different type of controls (e.g. ContentControl, TabControl), not Frame (see docs)
one more approach for simple navigation is ViewModel based.
Examples:
WPF MVVM navigate views
Navigation with MVVM by Rachel Lim (external)
I need to develop an multipage WPF application. I tried to achieve that by using one Window and multiple Pages. When I need to switch from one to another page I just change Content of main Window to point to that page. I have filling that I'm using wrong scenario because I don't have idea how to reuse XAML code for example an Menu controll, StatusBar and ToolBar for all pages.
You need ContentControl. It changes view based on ViewModel. Place your static elements in one place and in changeable area a ContenControl object.
More here and here.
One idea is you have a PageViewModelBase that implement a base virtual Property and Methods for Menu and StatusBar model and ... Then Each PageViewModel Override proper implementation of PageViewModelBase, Then Window contains Menu or StatusBar that Bind to DataContext of Pages.
Putting my requirement in very easy steps. Searched a lot on web but got very confused.
I got a Main Window (.xaml)
I got a Menu control, with Save option (a user control)
I got 3 more user controls (.xaml) in the same Window inside the Tab Control (with 3 tabs).
Each user control has data entries and has its own View Model class with Save() methods to save the data (implemented ICommand and INotifiyPropertyChanged in view model).
Now, if I have save button in individual usercontrol (inside the tabs) it works fine (I used commands for achieving this). But, I need the, Save to work, just clicking the "Save" on the menu, which is also a usercontrol and is inside the Main Window. The Menu save should act like a common Save for all the 3 user controls.
So the Menu should be now smart to identify which is the active usercontrol (probably based on the tab changed event or something else) and accordingly fire the Save() method for that usercontrol in the ViewModel.
Have you considered using Event Aggregator to accomplish communication between parts of your application without tightly coupling them.
im a bit new to wpf.
im trying to make the acclaimed Ribbon the center for all menus and commands of my custom app
now my main window is a tabcontrol with a few major tabs: contacts, sales, appointments,expense etc.
on top of the tabcontrol is a ribbon
(pretty similar to MS Outlook)
for each tab i have different buttons that i need
(the tabs each display a different UserControl as its main content)
plus there are several buttons that should always be in the ribbon (settings, about, new appointment...)
the best would be if i can add the RibbonTabs directly in the usercontrols and somehow merge them auto-magically with the main ribbon at runtime depending on the visible tab
if thats not possible then there is something called ContextualTabGroups, but for the life of me cant find any info on how to bind/trigger the different ribbons to certain cirmcumstances/childcontrols or whatever.
if i need to call .visibilty upon load and close of each usercontrol, then theres nothing "contextual" about that
thank you very much
I have a bunch of different objects that are commonly edited in the same TabControl using different DataTemplates, but I want each DataTemplate to have a common look and feel with Ok and Cancel buttons at the bottom right of each tab that will close the tab or save the content and then close the currently selected tab. What's the best way to place buttons on each tab ? Is there a way to do it without copying and pasting the buttons and stack panel across all of my data templates ?
Sure, you can create your own OkCancelSaveControl. In WPF, creating a "user control" is much easier than it sounds. Here is a tutorial. In a nutshell, you
create a new user control,
create properties in the user control that give the your control the information it needs to perform its duties (e.g. the tab that it's supposed to close or the data object that it's supposed to save),
if necessary, create events that the user control raises (OkClick), in case some tab requires special treatment.
I would make a custom control, lets call it MyCoolTabItem, that inherits from the TabItem class, and just throw your buttons into the control. Then just add a MyCoolTabItem instead of a TabItem to all of your TabControls and it will have all of your buttons on it.
You could make a base view class that held those buttons. Views that needed the buttons would inherit them and common functionality.