Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Custom renderer for dialog

$
0
0

Hi,

I'd like to create a custom renderer to display dialogs using platform specific dialog hosts. I'd like it to be able to take any arbitrary Xamarin Forms view as its content. I am first trying to implement the renderer on UWP. It looks like this.

public class WindowsDialogPageRenderer : IVisualElementRenderer
{
    public FrameworkElement ContainerElement => Control;

    public VisualElement Element => DialogPage;

    public event EventHandler<VisualElementChangedEventArgs> ElementChanged;

    public DialogPage DialogPage { get; private set; }

    public ContentDialog Control { get; private set; }

    public void Dispose()
    {
        Control.Hide();
        Control.Content = null;
    }

    public SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
    {
        return new SizeRequest(new Size(Control.Width, Control.Height));
    }

    public UIElement GetNativeElement()
    {
        return Control;
    }

    public async void SetElement(VisualElement element)
    {
        DialogPage = (DialogPage)element;
        var childRenderer = DialogPage.Content.GetOrCreateRenderer();
        var frameworkElement = childRenderer.ContainerElement;
        var dialog = new ContentDialog();
        Control = dialog;
        dialog.Content = frameworkElement;
        await dialog.ShowAsync();
    }
}

On dialog.ShowAsync(), I get an "argument does not fall within expected range" exception from UWP.

I have also tried implementing as a View/ViewRenderer, and get the same error.

Any hints or pointers?


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>