0

How to change the Button content as CamelCasing in Windows phone 8.1 Message dialog?

    private async void Button_Click(object sender, RoutedEventArgs e)
    {
        MessageDialog msg = new MessageDialog("Do you want to continue?");
        msg.Commands.Add(new UICommand("Ok", (command) => { }));
        msg.Commands.Add(new UICommand("Cancel", (command) => { }));
        await msg.ShowAsync();           
    }

enter image description here

I want to change the ok as Ok and cancel as Cancel.

Sankarann
  • 2,625
  • 4
  • 22
  • 59

3 Answers3

1

If you want a custom dialog you need to use a different control. The MessageDialog always lower cases the buttons to match the system style and is not generally customizable.

If you use a ContentDialog you can customize it fairly extensively, and it doesn't try to fix the case of its buttons. You'll probably want to create your own ContentDialog class (there's a template under Add.New Item...) with your desired contents, but here's a quick content-free example:

ContentDialog cd = new ContentDialog();
cd.Title = "My Title";
cd.PrimaryButtonText = "CoNtInUe";
cd.SecondaryButtonText = "sToP";
await cd.ShowAsync();

Also note that the guidelines for message dialogs suggest using clear and specific verbs rather than generic OK/Cancel.

Rob Caplan - MSFT
  • 21,714
  • 3
  • 32
  • 54
0

Use Content Dialog box like this:

Add this code inside your xaml.

    <ContentDialog x:Name="AlertMessage" Background="#363636" IsSecondaryButtonEnabled="True" SecondaryButtonText="Cancel"  IsPrimaryButtonEnabled="True" PrimaryButtonText="Ok" >
        <ContentDialog.Content>
            <StackPanel Name="rootStackPanel" Height="Auto"  >
                <StackPanel Margin="0">
                    <StackPanel Margin="0,0,0,10" Orientation="Horizontal">
                        <TextBlock x:Name="HeadingText" x:FieldModifier="public" Style="{StaticResource ApplicationMessageBoxHeadingStyle}" Text="Alert"  />
                        <Image Margin="10,05,0,0" Source="/Assets/Images/alert.png" Width="35"></Image>
                    </StackPanel>
                    <TextBlock x:FieldModifier="public" x:Name="ContentText" Style="{StaticResource ApplicationMessageBoxErrorStyle}" Text="Are you sure you want to log off ?" />
                </StackPanel>
            </StackPanel>
        </ContentDialog.Content>
    </ContentDialog>

And call this like that in your code:

    private void AppBarButton_Click(object sender, RoutedEventArgs e)
    {
        MessageBox();
    }
    private async void MessageBox()
    {
        ContentDialogResult LogoutDialog = await AlertMessage.ShowAsync();

        if (LogoutDialog == ContentDialogResult.Primary)
        {
            // User pressed Ok.
        }
        else
        {
            // User pressed Cancel or the back arrow.
            // Terms of use were not accepted.
        }
    }
Yawar
  • 1,924
  • 3
  • 29
  • 39
-1

Here is the code:

 CustomMessageBox messagebox = new CustomMessageBox()
 {
      Caption = "Do you want to continue?",
      LeftButtonContent = "Ok",
      RightButtonContent = "Cancel"
 };
Nitesh Kothari
  • 890
  • 12
  • 27