Common controls for UWP and WPF - c#

Is it possible to create common controls that can be used for both UWP and WPF applications?
Tried digging over the .NET and found out that code can be shared across them using .NET Standard but what about XAML controls/UI ?

You can't directly use WPF controls in UWP apps, as there are many features of WPF XAML which are not yet available in UWP. So direct forward compatibility is not available here. Evenso, upgrading existing WPF controls to UWP should not be too hard, usually all it takes is to rewrite some parts of XAML but the actual business logic behind them can be ported 1:1, as most is covered by .NET Standard.
However, at Build 2018 Microsoft announced UWP XAML Islands functionality, that will allow developers to upgrade the UI of WPF apps to modern UWP design, including Fluent Design System features. In the near future you will be able to do this with all UWP controls (including custom), once the APIs are ready, but currently you can at least use the modern UWP WebView control in WPF, which is part of the Windows Community Toolkit.

Related

Implementing of MediaPlayer and MediaTimeline in Windows Forms [duplicate]

Can both WPF and Windows forms controls be used within one application? How difficult or practical an idea is this?
It is fairly straightforward to host WPF controls in a WinForms app with an ElementHost adapter or WinForms controls in a WPF app with a WindowsFormsHost adapter. There are not too many resources on the web showing how to do either of these, however. In the process of learning how to do this for myself I quickly discovered the inherent symmetries between the two pathways. I distilled all my notes into an article comparing and contrasting these symmetries using a unique approach: the article is really two side-by-side articles, comparing every step in detail, starting from creating a user control in one technology to hosting it in an application in the "opposite" technology. My article, published on SimpleTalk.com in August 2010 is available here: Mixing WPF and WinForms.
For completeness, here are a couple good MSDN references, one for each pathway. In fact, the demo solution accompanying my article started from both of these:
Hosting a Windows Forms Composite Control in WPF
Hosting a WPF Control in Windows Forms
I believe there is a WindowsFormsHost control you can put in your WPF apps which will do interop back to WinForms code:
http://blogs.msdn.com/ivo_manolov/archive/2007/07/26/wpf-win32-interop-part-1-hosting-winforms-controls-in-wpf-windows.aspx
We hosted significantly complex WPF controls in an existing LOB WinForms app. It can be done, but we did have issues (some no doubt caused by the steep learning curve). These primarily had to do with loss-of-focus events not being fired when expected, and also keyboard navigation issues.
You can also use an HWNDSource and HWNDHost controls to embed WPF controls in a WinForms (or any Win32, really) app.
When hosting non-WPF content (Be it HTML, WinForms, or Win32 content), you will haveAirspace issues. This means you can't completely compost the WPF content with the hosted content. You also can't animate it etc. There are some interesting issues with respect to scrollviewers see here for more details and a fix also.
Yes you can, both Windows Forms within a WPF application, and WPF controls within Windows Forms. www.novamind.com's mind-mapping application is a successful mix of the two technologies.

Using WPF .NET APIs in a Windows 8.1 Universal application

As I am really really new to Universal Apps and I am coming from previous experience with WPF and Silverlight I was wondering if there is an approach I could use to take advantage of the .NET 4.5 APIs in an project created as Universal App. I know this might be a stupid question but as the idea of Universal Apps is to be "universal" it bright this thought to my head "Could I create a 'class library' for WPF and use it in an Universal App".
I have been researching this on the web but with no success so decided to test my luck here. Also if anyone could point me to some good resources in getting started with Universal app (for WPF/Silverlight .NET developers) it would be awesome.
You should be using Portable Class Libraries. It will give you the option to select which platforms to target. Keep in mind that the API surface available to Universal Apps are somewhat of a subset of the API surface available to WPF. This is somewhat analogous to how Silverlight was a subset of WPF in the beginning and then branched out somewhat over later versions.

Can I use WPF's Full-screen UI on Xamarin?

I'm thinking about starting to use Xamarin, is it possible to take a full-screen WPF project and use it on iOS and Android ?
No. Xamarin.Android and Xamarin.iOS expose the UI of the relevant platforms - you can't just use WPF on them.
However, if you separate out your "business logic" from the UI logic in your application, you may well be able to use the same business logic project, and just create new UI projects (one per platform). Of course, that relies on your "business logic" only requiring functionality which is available on Xamarin; more generally you'd want to create a Portable Class Library with that code in.
No this is not possible. You have to use the Native API's for User Interface on both IOS and Android when you use Xamarin.
You can definitely share a lot of code, but WPF will not work.
No. Xamarin relies on each platform's native UI stack. You cannot take a WPF UI (or a Winforms or Silverlight UI) and run it on iOS or Android. What you CAN do is take the underlying core of your WPF project (domain, services, data, business logic) and use Xamarin to create an iOS and/or Android native UI on top of it.
WPF is only supported on Windows - it's not even supported on other platforms with desktop APIs for Mono.
In general, with Xamarin, the approach is you share "logic" code, but use native UI projects for each platform.

WPF Plug-ins in Windows Forms application

I am used to WPF Development. But recently, i am assigned to Windows Forms projects. Fortunately, application framework supports pluggable architecture and that's why i feel i can develop plugin in WPF.
If we safely assume that framework doesn't need more than a interface to detect a plugin, I have following questions:
First of all, is it a good idea to develop WPF plugin for the given scenario?
Are there any guidelines available which i should follow? Any Examples?
Will it be a good idea to design some abstraction layer specially for WPF plugins rather than depending on interface?
Thanks in advance.
Yeah, we have huge project called "Plugins" which is basically WPF App/Windows loaded via additional app domain.
I think in your case depends if you Windows Forms are in .NET 2 or .NET3.5. If it is .NET 3.5 then you dont need additional app domain to load .NET 3.5 with WPF.
If you are already in .NET 3.5 with your WinForms, then you can use ElementHost to host your WPF inside WinForms.
Apart from few glitches (like not repainting the form sometimes), it went quite smoothly in our case
As to your Qs:
Usually it is better to do everything in WPF, but do u have a choice ? (I dont think so)
Lookup an example on WPF ElementHost
Well, I would use MVVM with WPF so that later on you can chnage the UI bit (maybe Silverlight or Win8 metro) without chnaging much of the business layer logic

The benefits and hassles of moving entirely to a WPF Project

I have a project that i started as a WinForms application as that was the format i was confortable with at the time. I have since started dabbling in WPF an introduced some WPF UserControls (mainly grids) into my project and absolutely love them.
The question i have is, is there any real advantage to me changing the UI Project of my solution into a purely WPF project, and get rid of any WinForms?
I am fully aware that each format suits a certain environment, and you wouldnt be able to give a definitive answer without knowing more of the details, but i would like to know peoples opinions, and if anyone has done a silimar thing of converting an existing WinForms App into a WPF frontend, and any observations they made in doing so.
Thanks
Underlying the new features in WPF is a powerful new infrastructure based on DirectX, the hardware-accelerated graphics API that’s commonly used in cutting-edge computer games. This means that you can use rich graphical effects without incurring the performance overhead that you’d suffer with Windows Forms. In fact, you even get advanced features such as support for video files and 3-D content. Using these features (and a good design tool), it’s possible to create eye-popping user interfaces and visual effects that would have been all but impossible with Windows Forms.
WPF enhances features that appeal directly to business developers, including a vastly improved data binding model, a new set of classes for printing content and managing print queues, and a document feature for displaying large amounts of formatted text.
But if you’ve done a substantial amount of work creating a Windows Forms application, you don’t need to migrate it wholesale to WPF to get access to new features such as animation. Instead, you can add WPF content to your existing Windows Forms application, or you can create a WPF application that incorporates your legacy Windows Forms content.
Reference: Pro WPF in C# 2008: Windows Presentation Foundation with .NET 3.5, Second Edition

Categories