Skip to content

Custom PageDialogService for Prism.Forms using Popup Pages

License

Notifications You must be signed in to change notification settings

fabcall/Prism.Plugin.PageDialogs

 
 

Repository files navigation

Prism.Plugin.PageDialogs

The Page Dialog plugin for Prims.Forms offers you the ability to quickly and easily add a Page Dialog Service that doesn't rely on the bland dialogs built into Xamarin for each platform. Instead you are able to provide a custom look and feel for each of your projects.

Build Status

Package Version
Prism.Plugin.PageDialogs 2

Platform Initialion

This plugin itself requires no platform initialization however you will need to initialize Rg.Plugin.Popup

In your Prism Application's RegisterTypes you need to do the following:

protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
    containerRegistry.RegisterPopupDialogService();

    // If you're using Prism.Plugin.Popups you don't need to do anything else
    // otherwise you can simply add the following:
    containerRegistry.RegisterInstance<IPopupNavigation>(PopupNavigation.Instance);
}

Customized Look & Feel

The built in ActionSheetPage and AlertPage have static properties which you can set at App startup to control the look of the built in pages.

protected override void OnInitialized()
{
    AlertPage.DefaultTitleBarBackgroundColor = (Color)Resources["PrimaryColor"];
    AlertPage.DefaultTitleStyle = (Style)Resources["AlertTitleStyle"];
    AlertPage.DefaultMessageStyle = (Style)Resources["AlertMessageStyle"];
}

Adding a custom Factory

In the event that simply providing custom default styles isn't enough, you can implement a custom IPopupDialogFactory. To control which style Dialog you simply need to set the Style property in either the ActionSheetRequest or AlertDialogRequest. The default PopupDialogFactory ignores the style key. The intent is that you are able to create an Alert or Action Sheet Dialog based on a Style key using.

public class MyFactory : IPopupDialogFactory
{
    public ActionSheetPageBase GetActionSheet(ActionSheetRequest request)
    {
        switch(request.Style)
        {
            case "Foo":
                return new FooActionSheetPage(request);
            case "Bar":
                return new BarActionSheetPage(request);
            default:
                new ActionSheetPage(request);
        }
    }

    public AlertPageBase GetAlertPage(AlertDialogRequest request)
    {
        switch(request.Style)
        {
            case "Foo":
                return new FooAlertPage(request);
            case "Bar":
                return new BarAlertPage(request);
            default:
                return AlertPage(request);
        }
    }
}

When using a custom Factory you can easily register both your factory and the PopupDialogService

protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
    containerRegistry.RegisterPopupDialogServiceWithFactory<MyFactory>();
}

About

Custom PageDialogService for Prism.Forms using Popup Pages

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 94.1%
  • PowerShell 5.9%