Xaml 从Xamarin.Forms中的依赖项服务将UWP页面推送到ContentPage上

Xaml 从Xamarin.Forms中的依赖项服务将UWP页面推送到ContentPage上,xaml,xamarin,xamarin.forms,uwp,Xaml,Xamarin,Xamarin.forms,Uwp,我正在处理一个xamarin.forms应用程序。在其中,我有一个依赖项服务,我想从中打开一个本机UWP页面(Windows.UI.Xaml.Controls.page)。这就像将一个页面推到ContentPage上,但我找不到合适的代码来实现这一点。请提出一些建议 从Xamarin.Forms中的依赖项服务将UWP页面推送到ContentPage上 当然,您可以使用DependencyService打开本机UWP页面,我将在下面发布实现 接口 public interface IOpenNat

我正在处理一个xamarin.forms应用程序。在其中,我有一个依赖项服务,我想从中打开一个本机UWP页面(Windows.UI.Xaml.Controls.page)。这就像将一个页面推到ContentPage上,但我找不到合适的代码来实现这一点。请提出一些建议

从Xamarin.Forms中的依赖项服务将UWP页面推送到ContentPage上

当然,您可以使用
DependencyService
打开本机UWP页面,我将在下面发布实现

接口

public interface IOpenNativeInterface
{
    void OpenNavtivePage();
    void BackToFormsPage();
}
private void Button_Clicked(object sender, EventArgs e)
{
    DependencyService.Get<IOpenNativeInterface>().OpenNavtivePage();
}
实施

[assembly:Dependency(typeof(OpenNativeImplemention))]

namespace CallNativePage.UWP
{
    public class OpenNativeImplemention : IOpenNativeInterface
    {
        Windows.UI.Xaml.Controls.Frame rootFrame = Window.Current.Content as Windows.UI.Xaml.Controls.Frame;
        public void BackToFormsPage()
        {

            if (rootFrame != null)
            {
                if (rootFrame.CanGoBack)
                {
                    rootFrame.GoBack();
                }
            }
        }

        public void OpenNavtivePage()
        {
       

            if (rootFrame != null)
            {
                rootFrame.Navigate(typeof(TestPage));
            }
            else
            {
                Window.Current.Content = new TestPage();
            }
            
        }
    }
}
用法

public interface IOpenNativeInterface
{
    void OpenNavtivePage();
    void BackToFormsPage();
}
private void Button_Clicked(object sender, EventArgs e)
{
    DependencyService.Get<IOpenNativeInterface>().OpenNavtivePage();
}

这真的很有帮助。多谢各位