How do I present Prism module views? - silverlight

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

Related

Best Starting Point for WPF Revit Add in

I am wanting to rewrite one of my Revit Add ins so that it utilizes WPF with MVVM because I like the look and functionality of WPF better than Windows Forms.
I have used the Revit Template Wizzard from Jeremy Tammik for the Form based add in, but adding a WPF user control seems not to work (a run time error that the xaml resource cannot be found).
I found a WPF MVVM revit add in example (AddMaterials, here is the github link, which will add materials from an Excel spreadsheet) but it does not follow what I am expecting to see at the top level.
Revit Add ins have an app.cs file which tells Revit how to register and access the DLL (ribbon panel buttons etc).
A windows WPF app will have app.xaml as the top level entry point.
The Add Materials project has neither which tells me that it must be
a class library, however the views are not using UserControls
rather they are Windows which I prefer. However Visual Studio does not
let you add a Window for a Class Library type project.
The third issue is easily solved by simply copying windows from a WPF application project into a class library project. But I don't really understand how the class library will instantiate in Revit without following the app.cs code from the template. Is anyone else creating add-ins this way, and if so can you let me in on any tricks or discussions that will help? Has anyone created a WPF Revit addin template for Visual Studio?
When I add a WPF window and try to instantiate it I get an error that it cannot find the xaml resource (System.IO.IOException: Cannot locate resource 'xxxx.xaml'). I have tried to fix this according to advice found when googling for this error, but to no avail. I am thinking it comes from being in a form based project, and that I may have to just start with a new project without the form stuff.
I have now verified that indeed you can start with the Revit AddIn Wizzard and use WPF . . . I started from scratch and copied in a window created in another project and got it to run (after adding the various references, namespaces, etc). So my problem seems to just be with the original project which already had a bunch of form stuff added.
Yes, I'm using WPF to create Revit Addins. It works well. You can easily create your own WPF template from the SDK samples:
Start with one of the Autodesk-provided SDK samples. I used the "DockableDialogs" sample. I know this one works, your mileage may vary with the others. If you're looking for windows rather than docked panes in the UI, another sample (perhaps the AddMaterials sample) is probably simpler.
I used Visual Studio to turn the sample into a template. File - Export Template -> select "DockableDialogs" or other WPF sample project.
Create a new project based on the template you just created. This was the easiest method I could find to get the WPF internal bits wired up correctly.
I'm not specifically familiar with the AddMaterials project, but to clarify your bullet points.
Revit Addins - It's not the file name (app.cs) but rather they must extend IExternalApplication or IExternalCommand. If you are creating a xaml interface (rather than just running a command from a ribbon button) you'll use 'IExternalApplication' as your entry point. Look for something like this in the sample:
public class ThisApplication : IExternalApplication ...
I don't used a top level app.xaml, but instead have page.xaml pages which are called by the Revit app. In my case these are Pages rather than Windows, which extend the IDockablePaneProvider class. These must be registered with the application which can then can be show, hide, etc your Panes. I imagine this is simpler with Windows, but haven't done it myself. For the dockable panes, your xaml.cs should start out something like:
public partial class MainPage : Page, Autodesk.Revit.UI.IDockablePaneProvider ...
Yes, the project is a class library in the sense that it is a collection of classes, at least one of which extends IExternalApplication or IExternalCommand. Remember that you're not creating a standalone application, but adding functionality to an existing Windows application (Revit). Revit will instantiate the ThisApplication class and then call its .OnStartup() method when the Revit application starts. This shouldn't stop you from adding .xaml or .cs files to the project, though. I can do it using VS Community 2015 using Ctrl-Shift-A.
Hopefully this gets you started - I've been able to implement a WPF UI in Revit without any prior WPF experience, and I'm not even a real programmer, so it's definitely possible. Good Luck!
addendum
If you want to add WPF elements to an existing revit addin, you can follow the instructions here: How can I connect xaml and xaml.cs files
Ultimately I found it easier to migrate my addin code into a template made from a working sample, you may want to try this approach as well.

PRISM + MEF: usercontrol or page?

For WPF Prism + MEF, most samples use usercontrol, is there any issue NOT to use page instead?
Well Pages are intended for XAML Browser Applications and should be contained inside Frame or a NavigationWindow. On the other hand UserControl can be contained inside a Window or another control.
XBAP run from Internet Explorer. Most samples apparently are not XBAP so that's why they don't use Page control. If it's what you want there is no problem using Page for Prism application. And MEF has nothing to do with this question.

Using ActiveX control in WPF

I'm attempting to host an ActiveX control in a WPF app. After attempting to use existing info on the web and here, I've hit a dead-end.
I need to use an ActiveX control provided to communicate with a UV power meter. They provide an application that registers and uses the control and even includes some useful demo apps. I stripped out the OCX file and put it here if needed. You won't have the power meter to talk to, but the app and demos will still load the ActiveX control successfully.
I created a simple Windows Forms application. I was able to bring the ActiveX control into the toolbar, drop it into my form, and everything is fine. The demo apps they provide do this as well.
However, getting this to work in a WPF environment is another story. The control can't be added to the toolbox and "dragged" into the app.
So far I've tried two techniques:
Technique found here. I am able to add a reference to the control, but then I enter namespace hell. The xmlns:ax namespace it suggests making cannot find the information. Here's my attempt based on what the object viewer tells me: xmlns:ax="clr-namespace:OphirUsbXLib;assembly=Interop.OphirUsbXLib"
Technique found here. This is essentially to create a new project that creates a library based on Windows Forms, which contains the ActiveX control (yikes). I am able to add the Windows Forms Host, but I cannot get access to the ActiveX control within. I can make the control public, but I still cannot call methods etc. This doesn't look like the right solution.
In short, I have an ActiveX control that works beautifully in Forms, but is a real bitch to get working in WPF.
Any insight is appreciated!
In this situation I would consider making a WinForms usercontrol which wraps the ActiveX control you are trying to use.
You could make public properties and methods which expose each of the required properties and methods on the ActiveX control, and then host this WinForms UC on the in a WPF WinFormsHost control.
I have already done something similar to this, in reverse, hosting a WPF UserControl in a WinForms UserControl, then hosting that on a VB6 Form in a legacy application.

WPF: Launch ModalDialog control from within XAML?

I'm building WPF client application. I'm following MVC pattern.
The project solution has many items, so I created „Views“ and „Controllers“ separate assemblies. „Views“ assembly references „Controllers“.
Problem: I need to load ShowModalDialog user control from withing controller instance which has no reference to View dialog control.
Is there a way to launch ModalDialog control from within XAML ?
AlbertasA
I ran into that same problem a while ago and there wasn't a built-in solution. This is a workaround I used: http://www.codeproject.com/KB/WPF/XAMLDialog.aspx

WPF how to integrate Ribbon in prism applications

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.

Resources