Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating add-ons for WPF applications

Tags:

c#

mvvm

wpf

prism

I have a simple database application where an user can add or delete persons. Moreover, the application has a button "Add new button to application". This application is built using Prism framework. There are two modules:

  • RibbonControlModule (contains three buttons - Add Person, Delete Person, Add new button to application)

  • PersonModule (contains logic of adding and deleting persons)

My requirement is to add new buttons at runtime.

Let's imagine a situation. I live in Washington and I am happy with these two buttons(Add Person and Delete Person). But my friend, Bob, who lives in New Jersey would like to add new button Edit Button without recompilation the whole application. That is, Bob writes dll where he can edit person and then clicks Add new button to application in RibbonControlModule. After that, EditPerson button is appeared in RibbonControl and, for example, in ContextMenu. Maybe EditPerson dll would be another Prism module, I do not know.

That is, my requirements are:

  • pluggable controls
  • is it possible to plug control without recompliation? (like add-ons or extensions(Classic Notes for Opera) in Browsers(no need to restart a browser to use add-ons))
  • other programmers can develop their add-ons without using my source code
  • after once an user plugged a control, then this new control should be always plugged in the application.

Is it possible using WPF, MVVM and Prism? I really like Prism and do not want to deny Prism, but if "the end justifies the means", I would like to use other technologies.

If it is possible, then how can I do it?

like image 822
StepUp Avatar asked Apr 22 '16 09:04

StepUp


People also ask

Is WPF still in demand?

However, some industries still rely on WPF concepts and tools like XAML & MVVM to develop futuristic web, mobile, and desktop applications. None of Microsoft's GUI frameworks ever really die. WPF has top-notch performance, with a high level of customization, and if you aim for Windows, both WPF is critical.

Is WPF harder than WinForms?

It is a little bit tough, time-consuming, and complex to use WPF as compared to WinForms.

Is WPF better than WinForms?

The single most important difference between WinForms and WPF is the fact that while WinForms is simply a layer on top of the standard Windows controls (e.g. a TextBox), WPF is built from scratch and doesn't rely on standard Windows controls in almost all situations.

How do I add apps to xaml to WPF project?

Go to add new items -> online templates and then choose 'Silverlight Application Class'. This will add a new app. xaml for you.


1 Answers

This is what the MEF plugin architecture was designed for.

In short, you create an SDK containing an interface for your plugins and provide that to your clients as a standalone library. Your client's plugins then implement this interface and export them with the MEF Export attribute, which your main application then imports.

Where it gets a little tricky is with data templating, which is often a key component of MVVM. To cut a long story short your plugins need to put their data templates in a resource dictionary, give that dictionary it's own partial class file and export it with MEF's [Export] attribute. Your main app then needs to import these and add them to the global ResourceDictionary's 'MergedDictionaries' array. This is generally done separate to all your view model classes which are imported in a separate pass. The net effect is that your plugins can provides both views and view models at runtime, plus the data templates that bind the two together, and it will all work as though they'd been statically compiled into your original application. It also means you can create a plugin API for your customers without exposing the internals of your main application.

This is a very involved topic, and given how general this question is I'll be surprised if this question isn't flagged. If you'd like more details then let me know and we can move it to a discussion page.

like image 175
Mark Feldman Avatar answered Oct 05 '22 10:10

Mark Feldman