C#:扩展WPF工具包 - 在MessageBox中自定义按钮标签

use*_*379 4 .net c# wpftoolkit

我想在我的wpf项目中实现一个消息框.文字是:"选择语言:"替代方案是英语(OK)和德语(取消).

在这种情况下,我试图自定义MessageBox中的按钮.为此,我尝试实现Extended WPF Toolkit,但在理解Extended WPF Toolkit的文档方面存在问题.

我的代码是这样的:

"Xceed.Wpf.Toolkit.MessageBox msgBox = new Xceed.Wpf.Toolkit.MessageBox();
msgBox.OkButtonContent = "English";
msgBox.CancelButtonContent = "German";
MessageBoxResult result =msgBox.ShowMessageBox("Choose Language: ", "Language",MessageBoxButton.OKCancel);"
Run Code Online (Sandbox Code Playgroud)

问题:

1)在wpf应用程序的用户可以选择的替代方案中,是否使用任何其他合适的控件?

2)在哪里可以找到一些很好的示例/文档来自定义消息框中的按钮标签?

pr0*_*g3r 6

只是在代码解决方案:

System.Windows.Style style = new System.Windows.Style();
style.Setters.Add(new Setter(Xceed.Wpf.Toolkit.MessageBox.YesButtonContentProperty, "Yes, FTW!"));
style.Setters.Add(new Setter(Xceed.Wpf.Toolkit.MessageBox.NoButtonContentProperty, "Omg, no"));
MessageBoxResult result = Xceed.Wpf.Toolkit.MessageBox.Show("My text", "My caption", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Yes, style);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


Y P*_*Y P 5

  • 创建您的消息框:

    MessageBoxResult _result = Xceed.Wpf.Toolkit.MessageBox.Show(this as Window, "Clear db?", "Import Question", MessageBoxButton.YesNoCancel, MessageBoxImage.Question, this.FindResource("ClearDbMessageBoxStyle1") as Style);
    
    Run Code Online (Sandbox Code Playgroud)

this你的 wpf 表格在哪里。

  • 在包含窗口的表单中:

    <Windows.Resources>
        <Style TargetType="{x:Type xctk:MessageBox}" x:Key="ClearDbMessageBoxStyle1">
            <Setter Property="YesButtonContent" Value="Clear db and import"/>
            <Setter Property="NoButtonContent" Value="append data"/>
            <Setter Property="CancelButtonContent" Value="Cancel"/>
        </Style>
    </Windows.Resources>
    
    Run Code Online (Sandbox Code Playgroud)

使用更多 setter,您可以使用 xaml 样式自定义更多内容。