Please login to access all of the features of the Community Site.

ShowAlert

Mobile20.0

Shows a native alert with a title, a message and one or two buttons. Use it to confirm an action before it happens, such as discarding changes, or to tell the person something they need to acknowledge. Each button can run a command when it's chosen.

The CommandParameter must be a ShowAlertParameters object. Give it only a confirm button for a single-button alert, or add a cancel button for a confirmation. If you leave out the confirm button, an OK button is shown.

Note

On iOS a destructive confirm button uses the system's red destructive style. On Android it shows red text. On Android, closing the alert with the back button or by tapping outside it counts as choosing cancel, so the cancel button's command runs.

Properties

ShowAlertParameters

PropertyTypeDescription
TitlestringThe title of the alert.
MessagestringThe message shown below the title.
ConfirmButtonAlertButtonThe confirm button. Defaults to a button titled OK that runs no command.
CancelButtonAlertButtonThe cancel button. Only shown when it has a Title. Leave it out for a single-button alert.

AlertButton

PropertyTypeDescription
TitlestringThe button text.
CommandICommandThe command to run when this button is chosen. Optional.
CommandParameterobjectThe parameter passed to Command. Optional.
IsDestructiveboolShows the button in red to warn that the action can't easily be undone. Only applies to the confirm button. Defaults to false.

Examples

<Button Text="Save"
    Command="{Binding ShowAlert}">
    <Button.CommandParameter>
        <Rock:ShowAlertParameters Title="Saved"
            Message="Your changes have been saved." />
    </Button.CommandParameter>
</Button>
<Button Text="Discard"
    Command="{Binding ShowAlert}">
    <Button.CommandParameter>
        <Rock:ShowAlertParameters Title="Discard changes?"
            Message="Your changes will be lost.">
            <Rock:ShowAlertParameters.ConfirmButton>
                <Rock:AlertButton Title="Discard"
                    IsDestructive="True"
                    Command="{Binding PopPage}" />
            </Rock:ShowAlertParameters.ConfirmButton>
            <Rock:ShowAlertParameters.CancelButton>
                <Rock:AlertButton Title="Keep Editing" />
            </Rock:ShowAlertParameters.CancelButton>
        </Rock:ShowAlertParameters>
    </Button.CommandParameter>
</Button>