Telerik UI for Windows Phone by Progress

Examples

Specifying arbitrary text for the buttons:

CopyC#
RadMessageBox.Show(new string[] { "Button1", "Button2", "Button3", "Button4" }, "Title");

Specifying a custom template for the buttons:

CopyXAML
<DataTemplate x:Key="ButtonsTemplate">
<telerikPrimitives:RadWrapPanel x:Name="PART_ButtonsPanel" />
</DataTemplate>
CopyC#
DataTemplate buttonsTemplate = (DataTemplate)this.Resources["ButtonsTemplate"];
RadMessageBox.Show(buttonsTemplate, "Title", new string[] { "Button1", "Button2", "Button3", "Button4" });

It is very important that the panel inside the data template has its name set to "PART_ButtonsPanel". This is a required part of the control and if it is not present, RadMessageBox will not work.

Creating a control template for RadMessageBox:

CopyXAML
<ControlTemplate x:Key="ImageTemplate" TargetType="special:RadMessageBoxControl">
<Border Padding="12" Background="{StaticResource PhoneChromeBrush}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ContentControl x:Name="PART_Title" HorizontalContentAlignment="Left" FontSize="{StaticResource PhoneFontSizeLarge}" FontFamily="{StaticResource PhoneFontFamilySemiBold}" Margin="{StaticResource PhoneMargin}" />
<StackPanel Grid.Row="1" Orientation="Horizontal">
<Image Source="SomeImage.png" Margin="12, 12, 0, 24" />
<ContentControl HorizontalContentAlignment="Left" VerticalContentAlignment="Top" x:Name="PART_Message" Margin="12, 12, 12, 24" />
</StackPanel>
<CheckBox x:Name="PART_CheckBox" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Bottom" />
<ContentControl Grid.Row="3" x:Name="PART_ButtonsContainer" HorizontalContentAlignment="Stretch">
<ContentControl.ContentTemplate>
<DataTemplate>
<StackPanel x:Name="PART_ButtonsPanel" Orientation="Horizontal"></StackPanel>
</DataTemplate>
</ContentControl.ContentTemplate>
</ContentControl>
</Grid>
</Border>
</ControlTemplate>
CopyC#
ControlTemplate imageTemplate = (ControlTemplate)this.Resources["ImageTemplate"];
RadMessageBox.Show(imageTemplate, "Title", new string[] { "yes", "no" });

Calling the Show method only with the required arguments:

CopyC#
RadMessageBox.Show("Title", vibrate: true, verticalAlignment: VerticalAlignment.Stretch);

The RadMessageBox.Show() method can be called as succinctly as possible with the aid of named arguments. Notice how each argument after the first is specified by name.

Determining which button was pressed:

CopyC#
RadMessageBox.Show("Message", closedHandler: (args) =>
    {
        /*
         * The args parameter in closedHandler gives us three types of information
         * regarding which button was pressed.
         */

        // The Result property returns either OK or Cancel depending on whether the first
        // button in the buttons panel was pressed or a different one. This is equivalent
        // to checking if the ButtonIndex property is 0 or not. 0 = OK, non-zero = Cancel.
        DialogResult result = args.Result;

        // The ButtonIndex is the index of the pressed button in its parent's Children collection.
        // For example if the buttons are arranged in a vertical stack panel. Tapping on the top-most
        // button will result in ButtonIndex = 0, tapping on the second button in ButtonIndex = 1 etc.
        int buttonIndex = args.ButtonIndex;

        // Finally, the args parameter gives a reference to the actual button that was tapped via the
        // ClickedButton property.
        Button clickedButton = args.ClickedButton;
    });