如何在 Windows phone 8.1 消息对话框中将按钮内容更改为 CamelCasing

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

如何在 Windows phone 8.1 消息对话框中将按钮内容更改为 CamelCasing?

    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();           
    }

我想把ok改成Ok,cancel改成Cancel。

代码如下:

 CustomMessageBox messagebox = new CustomMessageBox()
 {
      Caption = "Do you want to continue?",
      LeftButtonContent = "Ok",
      RightButtonContent = "Cancel"
 };

如果您想要自定义对话框,则需要使用不同的控件。 MessageDialog 始终将按钮小写以匹配系统样式,并且通常不可自定义。

如果您使用 ContentDialog,您可以对其进行相当广泛的自定义,并且它不会尝试修复其按钮的大小写。您可能希望使用您想要的内容创建自己的 ContentDialog class(Add.New 项下有一个模板...),但这里有一个无内容的快速示例:

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

另请注意,guidelines for message dialogs 建议使用明确且具体的动词,而不是通用的 OK/Cancel。

像这样使用内容对话框:

在您的 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>

然后在您的代码中这样调用:

    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.
        }
    }