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

时间:2015-02-05 11:03:02

标签: windows-phone windows-phone-8.1 messagedialog

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

enter image description here

我想将ok更改为Ok并取消取消。

3 个答案:

答案 0 :(得分:1)

如果需要自定义对话框,则需要使用其他控件。 MessageDialog总是会降低与系统样式匹配的按钮,并且通常不可自定义。

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

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

另请注意,guidelines for message dialogs建议使用明确的和特定的动词,而不是通用的确定/取消。

答案 1 :(得分:0)

使用内容对话框,如下所示:

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

答案 2 :(得分:-1)

以下是代码:

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