Create catalog for WPF and Silverlight from XAML - silverlight

I am developing application for WPF and Silverlight by ProjectLinker with PRISM and MEF modularity.
My modules are Class Library (in WPF) and Silverlight Class Library (in Silverlight).
Now I want to load modules in WPF or Silverlight by Catalog.xaml from server.
Problem is:
- Silverlight cannot load DLL but only XAP
- WPF cannot load XAP but only DLL
How can I do that - developing by project linker (same code for both platforms), create modules, download from server and load to application?
I have in bootstrapper:
On server WCF I have Catalog.xaml - I download it and...
catalog = Microsoft.Practices.Prism.Modularity.ModuleCatalog.CreateFromXaml(stream); - it works
But If I run application by the load module I have an error (I tried to load DLL to Silverlight).
Thanks

Try this link from the PRISM website: Sharing Code Between Silverlight and WPF
For the Module catalogs, you will either need to create separate XAML files, or use possibly use TT files to generate them from a common set of module names.
As you need to carefully specify the dependencies for Silverlight to get the best start times, you might be better off maintaining separate files.

Problem was on type of project. Project for silverlight must be as Silverlight application. So I changed type of silverlight project and now build for WPF is DLL and for silverlight is XAP. It is working.

Related

Using Mahapps.Metro Flyouts in Elementhost

I'm writing a SolidWorks addin, where I can host WPF only within an Winforms Elementhost. Now I want to use a Flyout from Mahapps.Metro, which depens on being hosted in a MetroWindow. Is there any way I can use the Flyout from within a WPF Usercontrol? I'm using .NET 4.6.2, Mahapps.Metro 1.6 and SolidWorks 2018.
Looks like the Information I found here and here is obsolete. I just installed the NuGet Packages Mahapps.Metro and Mahapps.Metro.Iconpacks and everything is working as expected.
If someone is trying to do it in a SolidWorks Addin too, make sure to manually load a new version of System.Windows.Interactivity, because Solid is loading an old version from the application base directory, which is not compatible with Mahapps.Metro!
Be very careful when you are working with .NET add-ins for solidworks. If your application uses some third-party UI lib, you need to copy those referenced assemblies to the host application (sldworks.exe) directory. For some reason, the domain application is that of hosting exe and not the dll. CLR will look for references in the sldworks.exe's directory and it doesn't find, the application throw some nasty exception that will crash your SOLIDWORKS.

Errors when referencing Silverlight class library from WPF application

I have a WPF application and a Silverlight application. They are both used to display a map and share some of the same functionality.
I have created a Silverlight class library project in order to stay DRY. I'm referencing this from both Silverlight and WPF. It contains some utility methods that are useful in both projects. For example, I have this method:
public static void CenterText(TextBlock name, Polygon poly)
The silverlight project has no problem with this. However, I get the following error when calling this from my WPF application:
The type 'System.Windows.Shapes.Polygon' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'
However, I have this line at the top of the file:
using System.Windows.Shapes;
so WPF can see the Polygon class perfectly fine.
My guess is that the silverlight class library uses a version of the framework which is not compatible with the version that the WPF project is using.
So the question is, am I stuck rewriting exactly the same code in my WPF application or is there some way I can share between the two?
Thanks!
You are right, Silverlight uses a completely separate version of the framework. It's much, much smaller than event the .NET client runtime.
This means you can't mix WPF and Silverlight assemblies in the same application.
I ran into this error because I had downloaded the Expression Blend SDK for Silverlight instead of what I SHOULD have downloaded: Microsoft Expression Blend Software Development Kit (SDK) for .NET 4. It can be found on MSFT's website, here:
http://www.microsoft.com/en-us/download/details.aspx?id=10801
As soon as I downloaded the Expression Blend SDK for .Net, removed all of the Blend SDK for Silverlight references, and added those same references as Blend for .Net, I was up and running.
In Silverlight the class is in System.Windows.dll while in WPF it is in PresentationFramework.dll the library tries to get a hold of the Silverlight assembly which is not referenced by default in a WPF application.

How to call method written in C# class library from Silverlight application(xaml.cs file)?

Can a Silverlight application call a method in a full .NET c# class library?
I am trying to add a Silverlight control to my Existing ASP.NET project where i used to add reference to my Business Logic Project and access methods from My UI pages of ASP.NET Web application. Now I have added one Silverlight project to my solution.
How can I use the already existing BL method which is in a C# class library ? When tried to add reference, it is saying that
"You can only add project reference to other silver light projects in the solution".
Should i give up ? Is there any way to get rid of this ?
A common method to achieve this is to build a silverlight library that links in all the files from your Business Logic library. This way the code is written once, and built twice. To link the files go to Add Files in Visual Studio and select the drop-down arrow on the Add button. Select Add as Link.
Alternatively Silverlight 4 and .NET 4 have binary compatible assemblies, so as long as the code in your main Business Logic library is fully Silverlight compatible you should be able to use the library as a reference there.

Silverlight application vs class library projects

I'm getting started with Silverlight. When creating a new solution I have the option of creating a Silverlight Application or Silverlight Class Library. The Application option sets everything up for me but class library is quite sparse.
I'm trying to work out which one do I start with? Particularly I'm uncertain about when I would use SharePoint Class Library and what benefits/restrictions it has over Silverlight Application.
I'd like to write a control that I can put either a plain ASP.NET or Silverlight UI on top of, with both talking to the same back end.
The Silverlight Application template will create a shell UI with necessary project configuration to launch a Silverlight application. You have the option of creating an asp.net or plain html-based Silverlight application. The Class Library template, like the non-silverlight counterpart, is UI-less component that the Silverlight application can consume. You will not be able to reference regular class libraries, or sharepoint class libraries from a Silverlight applications as framework requirements are different ... Silverlight relies on stripped-down framework that is not compatible with full .NET release at this time.
So, in order to develop a Silverlight application, you need to start with Silverlight Application template, which then can reference any number of Silverlight Class Libraries, depending on your project layout or architecture.
If you want to write components that you can either snap an ASP.NET UI or Silverlight UI, you will need to create either a Class Library (for ASP.NET) or Silverlight Class Library (for Silverlight). You will not be able to reference Silverlight Class Library from ASP.NET, or reference Class Library from Silverlight. However, you can share the code between the different class libraries by linking source code files between them.
ib.

WPF - Switching from WPF app to xbap

I have a working WPF application. I would like to see it running as an xbap. What do I need to change in my WPF app to make it run as an xbap?
When it comes to what you can do graphically, the only difference between the two is that XBAP can't use BitmapEffects. Other than that, the sandbox security issues are pretty much the only things you need to deal with. Most pure WPF programs should transition smoothly.
Check out this comparison of the differences between WPF and XBAP.
Here's a tutorial for creating an XBAP application.
Based on that there's a fairly simple refactor you can do to accommodate both WPF and XBAP for your program.
First, move all of your WPF code into
a .dll project separate from the core
WPF EXE project. Reference this project in your core WPF EXE project.
Modify the EXE project's App.xaml to point to
your main page from your .dll
project.
Create a new XBAP project.
Reference the dll project mentioned above in your XBAP project
Modify the XBAP project's App.xaml to point to the main page from your .dll
Publish and run.
Yes, we can use Windows in XBAP.
But the first object must be a Page, because the Page will be displayed on the browser. You can put a button on the page and open your window from it.

Resources