简体   繁体   中英

Is there any possibility to launch a Xamarin.Forms App in a WPF User Control?

So I am trying to launch a Xamarin Application for a preview in a UserControl.

The reason for this is, that we have an application where we have a own description language to define custom scenes on our product and we need some kind of preview where the user can see the current scene. This scene will be send to different client types this includes a Xamarin Android App.

What I have tried was to use Xamarin.Forms.Platform.WPF, which worked perfectly, until I wanted to make it into a UserControl. The documentation says to use the tag:

<FormsApplicationPage>

And start the application like:

using Xamarin.Forms;
using Xamarin.Forms.Platform.WPF;

namespace BoxViewClock.WPF
{
    public partial class MainWindow : FormsApplicationPage
    {
        public MainWindow()
        {
            InitializeComponent();

            Forms.Init();
            LoadApplication(new TestApp.App());
        }
    }
}

The problem is, that the class is a WPF Window, which is problematic for us, because we want it to integrate it into our existing WPF Application in the same Window. The second Problem is, when you execute LoadApplication(new TestApp.App()); the whole window will get overridden.

So is there any way to use a Xamarin App with Xamarin.Forms.Platform.WPF as a UserControl?

It depends on how you define 'possible'.

Xamarin.Forms is open-source, and it is certainly possible to achieve what you want by modifying some of their code here: https://github.com/xamarin/Xamarin.Forms/tree/main/Xamarin.Forms.Platform.WPF

However if you think whether Xamarin.Forms officially support that, the answer is no.

Finally if you think whether someone has made something like that in the community, I am not aware of that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM