【问题标题】:C#: Extended WPF Toolkit - Customixing Button Labels in a MessageBoxC#:扩展 WPF 工具包 - 自定义消息框中的按钮标签
【发布时间】:2013-09-23 04:44:05
【问题描述】:

我想在我的 wpf 项目中实现一个消息框。 文本是:“选择语言:” 替代方案是英语 (OK) 和德语 (Cancel)。

在这种情况下,我正在尝试自定义 MessageBox 中的按钮。为此,我尝试实现扩展 WPF 工具包,但在理解扩展 WPF 工具包的文档方面存在问题。

我的代码是这样的:

"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);"

问题:

1) wpf 应用程序的用户是否可以选择其他合适的控件?

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

【问题讨论】:

  • Xceed.Wpf.Toolkit.MessageBox 没有定义构造函数

标签: c# .net wpftoolkit


【解决方案1】:
  • 创建您的消息框:

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

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>
    

有了更多的 setter,你可以使用 xaml 样式自定义更多。

【讨论】:

    【解决方案2】:

    代码解决方案:

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

    【讨论】:

      【解决方案3】:
      <Application.Resources>
          <ResourceDictionary>
                <!-- Here -->
          </ResourceDictionary>
      </Application.Resources>
      

      在资源字典中添加:

              <Style TargetType="{x:Type toolkit:MessageBox}">
                  <Setter Property="Background" Value="White" />
                  <!-- <Setter Property="BorderBrush" Value="Red" /> -->
                  <Setter Property="CaptionForeground" Value="White" />
                  <!-- <Setter Property="WindowBorderBrush" Value="Blue" /> -->
                  <Setter Property="WindowBackground" Value="#FF33A133" />
                  <!-- <Setter Property="WindowOpacity" Value="0.3" /> -->
                  <Setter Property="Foreground" Value="Purple"/>
      
                  <!-- Setter Button content -->
                  <Setter Property="YesButtonContent" Value="Si"/>
                  <Setter Property="NoButtonContent" Value="No"/>
                  <Setter Property="CancelButtonContent" Value="Cancelar"/>
              </Style>
      

      更多信息

      https://wpftoolkit.codeplex.com/wikipage?title=MessageBox&referringTitle=Home

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-08-20
        • 2012-03-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多