Using Mahapps.Metro Flyouts in Elementhost - wpf

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.

Related

Using AdControl to display ads in a WPF application packaged for UWP

I (appear to) have successfully created a UWP package for my WPF application using the following guide:
https://learn.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-packaging-dot-net
Now I would like to take advantage of the AdControl class to display banner ads in my project, as detailed here:
https://learn.microsoft.com/en-us/windows/uwp/monetize/adcontrol-in-xaml-and--net
Is this possible? I don't see the "Universal Windows" section under References for my WPF project, which I can guess is because it’s not an original Universal Windows project. I do see it under References for the UWP package wrapper project I created using the guide above, but that doesn't help me show ads in the WPF project.
Any help appreciated.
You can add Universal Windows reference and use the API in your project as described here but you cannot use AdControl since XAML/UI in WPF is not the same as XAML in UWP and the AdControl is a UWP XAML control:
As mentioned above, there are exceptions to the rule that Windows 10
APIs are accessible from PC software. The first big exception concerns
XAML UI APIs. The XAML framework in UWP is different from the one in
WPF and you really don’t want to be mixing them up, anyways.

Create catalog for WPF and Silverlight from XAML

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.

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.

putting some WPF windows in DLL

I have a WPF project, and there is one dialog that I will re-use in different applications. I want to put it in its own DLL, but when I use the New Project wizard in Visual Studio 2008 it only lets me create WinForm C# DLLs. Am I missing something?
You should be able to create a WPF Custom Control Library project.
To add to this, this particular project does not actually show up unless you specifically choose Classic Desktop projects.

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