WPF - Switching from WPF app to xbap - wpf

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.

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.

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.

Convert wpf application to wpf browser application

Is it possible to convert wpf desktop application to wpf browser application? I want to make my application run from browser.
According to my experience there is no converter available which converts WPF to XBAP.
But I did work with multiple platforms together several time in my project. I do maintain 3 platforms together WPF, Silverlight and XBAP in a single solution having single code base. I keep a common code-base and share files between 3 platforms. To achieve this I suggest you to create a Hello world XBAP application and run it first. You need to have few basic idea about how an XBAP application works. Initially understanding the entry and exit point of the application will be enough for you. Try adding one button in Page and understand how it works. Once it’s done then try to link the existing project files (XAML and CS) one by one into the XBAP project. Understand what you are adding and why are you adding. Yes it's quite a hard work you need to do. But don’t worry XBAP, WPF XAML & C# codes are almost similar. You need to know that Conditional compilation symbols can be set in project properties. So that you will be allowed to write #if XBAP & #endif statement in your code sometimes, because few classes or features may not be supported in XBAP and you need to write specific code for XBAP. As an example Dropshadow related features are not available in XBAP.
Hope this answers your query!

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.

Loading a WPF form into a MFC application without /clr

I am trying to integrate WPF into a legacy MFC application. I am unable to include the /clr switch to mix managed and unmanaged due to the restrictions of other projects in the solution. I need the WPF window open up as a child window in the main MFC application. I have been investigating different ways for the past two weeks but have hit roadblock with every implementation try. If anyone has successfully integrated this type of implementation, I would appreciate some direction. I have been able to integrate with a Win32 app, but could not translate this to an MFC app. Thanks everyone.
I believe that WPF requires .NET, therefore what you need is to create a separate DLL or EXE for the WPF parts. hat new project could be the container for .NET code and your main MFC would launch this separate project.
You can write a WPF front end that launches C++ apps with the desired command like switches, similar to what Visual Studio 2010 is doing to compile your code and show the results in the output pane. In this way you can avoid having to hack message loop code to support both frameworks .
You may show your Dialog using a COM interface

Resources