WPF how to integrate Ribbon in prism applications - wpf

I'm writing a prism application and would like to integrate Ribbon library in it. I want a Ribbon Window that would be used as a Shell with office-like tabs and tab groups. The modules should be loaded on demand depending on the tab selected by user. I don't want the tabs to be located in a region if this is avoidable. So I created a Ribbon window and some regions and get all kind of errors (cannot resolve dependency object, etc.). Is there somewhere a good example of such application or a tutorial? How to load the modules depending on the user's choice?
I started this thread but I didn't get an answer that could help me.
Thanks for any help and suggestions.

Have you implemented a RegionAdapter for the Ribbon? (I'm guessing you're trying to fill the Ribbon dynamically with a Region attached property)
See this link for details.

Make your shell a RibbonWindow and if you need commands over the whole application you can create applicationcommands.

Related

How do I display a user control registered by path in main window using Castle (WPF)

I have a WPF application with Castle design. In my main window project I perform registration on all of my other projects.
I would like to avoid referencing some projects which holds User Control and still display them in my main window.
So I am using the Register By Folder for now and I do not understand how the xaml of the main window can know these user controls if they are not referenced?
Please Advise
Adi.
If your main window project registers all components you will have to reference all of your control projects from it. If you want to avoid this you will need to have a bootstrap project.
Check out how Krzysztof Koźmic uses DI, it might give you a few ideas.

Prism and MVVM for new WPF project

I will be starting a new project soon and am looking for some architectural advice from those of you who have experience with WPF, Prism, and MVVM.
The project will definitely be WPF and I will be implementing MVVM (I will likely use Josh Smith's MVVM Foundation as a starting point) in order to be able to benefit from the separation of UI/logic etc. I am not sure though if I would benefit from using Prism as well to structure my project.
Let me briefly describe the project. There will be a main "toolbar" that will display a number of widgets. Each widget displays some basic data related to its function and clicking the widget will open a new window that will display much more detailed data and contain a rich UI for viewing/editing the data.
Now, I was thinking that I can use Prism to frame the project but I have never used it before and am not sure if it is suitable for what I am trying to achieve. For example, would my "toolbar" be a shell that contains regions that each widget would populate? Would each new window that is displayed when a widget is clicked also be its own shell with its own region setup? If I can get the pattern down for the toolbar and one widget on the toolbar, I can replicate it for the rest of the widgets.
Aside from Prism, I have a question about how MVVM should be implemented for certain data editing windows. Let's say I have a chart that displays some data and the user is able to directly click/mouse move on the chart to edit the data that he sees. All of the data is in the model and the view model is making that data available to the view via binding. My question is where will the mouse click/move events, that are specific to the chart in that view, be written? We don't want much/anything in the view's code behind and we don't want to have UI event handlers in the view model so I am not sure how this type of scenario is handled. I know that commands are the likely answer here but the MVVM samples I have seen usually show sample commands for simple button clicks. Is the general idea the same?
So, if anyone has any suggestions on the above or any general tips on working with WPF and MVVM/Prism, please let me know.
Thank you.
There are a few questions in there so I will do my best at covering them all.
I worked on a project that had WPF, MVVM, and Prism along side other frameworks. The best advice is to understand the power and functionality of each before glueing it all together. You don't have to use all the features of Prism for it to be useful in this situation.
For Prism you can use...
Shell and bootstrapper to initialise the application and load modules from other assemblies.
Create and configure Unity for Dependency Injection. You can use other DI Containers. Here you can add global services each module will use.
Use of EventAggregator to notify differnent parts of the application, usually across modules and views
Regions for naming areas on the UI so modules can add a view to a particular location.
The above 4 don't all have to be used but can easily be integrated in a MVVM /WPF application.
For example, would my "toolbar" be a
shell that contains regions that each
widget would populate?
Here you can have a region you create (you can derive from Region) that will manage the buttons on the toolbar. (I have used a region with regards to a Ribbon). A service can be exposed via an interface that each module can supply the command/image (what ever you have) that when it is clicked will create a ViewModel. You can do this inside the module's Initialisation.
Would each new window that is
displayed when a widget is clicked
also be its own shell with its own
region setup?
If each button opens a brand new window I would suggest introducing a common controller class that will create a generic use window and attach a view model that your module creates. No real need to use regions in this case unless you are gluing different views to a application window that stays open longer than the life of the view itself. The window in basic form can simply be this...
<Window ...>
<ContentControl Content="{Binding}" />
</Window>
Where within your controller it can do this...
public void DisplayView(ViewModel vm)
{
var window = new MyWindow { DataContext = vm };
window.Show();
}
The controller can be used within your module directly of wrapped within a service... although for testabilty a service and interface would be best. Make sure you have merged your module resources with the Applicaiton.Resources and use DataTemplate's to link your view to the view model.
My question is where will the mouse
click/move events, that are specific
to the chart in that view, be written?
Don't be afraid of code behind but you can in this case use EventToCommand attached behaviour that will route to a command on your viewmodel. MVVMLight toolkit has this which you can reuse if you want.
DI is very powerful and I encourage using it even without Prism as constructing your view models will be easier.
HTH
I think Prism will work great for you.
->would my "toolbar" be a shell that contains regions that each widget would populate?
Put a single region with an ItemsControl in the Shell
Create modules for each widget
Keep adding the widget modules to the same itemscontrol shell region.
The biggest advantage with this is that if you add more modules you don't need to change anything.
->Would each new window that is displayed when a widget is clicked also be its own shell with its own region setup?
No, you can use a 'WindowRegionAdapter' in the shell to create views for your widgets in separate windows.
->where will the mouse click/move events, that are specific to the chart in that view, be written?
You can use attached behaviors to bind events in your view to commands in the ViewModel purely in XAML. Google 'Blend behaviors' or 'attached bahaviors' for how you could go about doing it. There is no need to write any code behind for this.
To be honest I am only trying to give you the keywords you'd want to search to get all the information you need.

With WPF Prism can you prevent two modules from trying to use the same region simultaneously?

Here is the overview of what I am trying to do. I have a region in the shell that is used for application modal dialogs. When a module wants to launch an application modal dialog it loads a custom Lightbox control into the region and fills it with the content I want to display (warning, wizards, etc). I have the region defined in the shell because I assume it needs to be there for the lightbox background to block out the whole window.
The immediate situation that comes to mind is what happens if two modules trying to use the region at the same time, is there any prismy way of preventing another module from accessing a region until after the current use of the region is finished?
If there are better ways to accomplish what I want I am open to suggestions.
You could use the RegionPopupBehavior from the Prism RI to display dialogs and have the dialog's content set as views into regions.
You can read more about that here: http://compositewpf.codeplex.com/Thread/View.aspx?ThreadId=65394.
I hope this helps.
Thanks,
Damian

How do I present Prism module views?

I'm writing a prism application, I've just created my 1st module, fired it all up and amazingly - it works.
The application is going to grow soon(TM), and I'll be facing the need to host those modules in separate GUI elements.
What type of GUI elements would you recommend to host the modules?
Is it possible to data-bind a module to some control like a tab-control? How is it done?
Is there some kind of a dock manager (similiar to AvalonDock) for Silverlight?
Have you looked at StockTrader sample project provided with PRISM? It has in Shell.xaml AnimatedTabControl (inherited from TabControl) to which are bound modules: WatchModule (look at WatchListController.cs file) and PositionModule (look at PositionModule.cs file).
[Edit]
Take a look also at Prism Explorer sample project, which is using TabControl in Shell.
There IS dock manager, check silverlight toolkit ( it is installed with sl4 or you can take it here )
Also there is an example of binding controls to tab control tabs with MEF on channel 9

WPF Ribbon and Plugin

I'm looking into using the Office Ribbon UI to help navigate around my application and provide different tools for the current selected tab.
I need the Ribbon to be plugable. Each plugin has its own tab and using a DataTemplate displays what's needed.
The main control area will have a navigation on the left and a Tab Control on the right. Multple tabs will be open most of the time.
Ok questions:
1. Is the Ribbon control the correct control for the job
2. How do i dynamically add Tabs to the Ribbon control through my View Model
3. Does anyone know how to define DataTemplates in an external assembly. I need to avoid configurations inside my main application IE make it plugable :D
FYI. The application is a POS system
The Office Ribbon was the wrong choice for my design.
I've seen posts on using Prism with Office Ribbon to get plugins working

Resources