如何在UWP ContentDialog中加载Xamarin Forms ContentPage?

时间:2018-11-08 02:00:34

标签: xamarin.forms uwp

我正在Xamarin Forms中创建自己的ProgressDialogService,并且让Android服务正常工作并呈现一个对话框叠加层,该对话框使背景变暗并显示我的ProgressDialog(Xamarin Forms ContentPage)。我几乎也可以使用UWP服务,但无法找出在UWP ContentDialog中加载/渲染Xamarin Forms ContentPage的正确方法。

我知道我可以在UWP中创建一个单独的Page并将其用作ContentDialog,但是我想利用Xamarin Forms的强大功能,并且在两个平台中都使用相同的ProgressDialog。

这是我到目前为止所能完成的工作,但是看起来有点可笑。我知道我还需要调整大小,但是为什么它会变得怪异?例如,文本看起来不清晰,并且所有内容看起来都太大了。

想知道我是否在正确的轨道上吗?欢迎任何输入!

private void InitProgressDialog(ProgressDialog progressDialog = null)
{
    _progressDialog = progressDialog;

    // check if the page parameter is available
    if (_progressDialog != null)
    {
        // build the loading page with native base
        _progressDialog.Parent = Application.Current.MainPage;

        _progressDialog.Layout(new Rectangle(0,
                                             0,
                                             Application.Current.MainPage.Width,
                                             Application.Current.MainPage.Height));

        _progressDialog.CancelButtonClicked += ProgressDialog_OnCancelButtonClicked;

        var renderer = Platform.GetRenderer(progressDialog);

        if (renderer == null)
        {
            renderer = Platform.CreateRenderer(_progressDialog);
            Platform.SetRenderer(_progressDialog, renderer);
        }

        var panel = new StackPanel();

        panel.Children.Add(renderer.ContainerElement);

        _dialog = new ContentDialog { Content = panel };

        _isInitialized = true;
    }
}

enter image description here

0 个答案:

没有答案
相关问题