5

I would like to implement a message box in my wpf-project. The text is: "Choose Language:" The alternatives are English (OK) and German (Cancel).

In this context, I am trying to customize the buttons in the MessageBox. For doing this, I try to implement the Extended WPF Toolkit, but I have problems in terms of understanding the documentation for the Extended WPF Toolkit.

My code is like this:

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

Questions:

1) Are the any other suitable controls to use where the user of the wpf application can choose among alternatives?

2) Where do I find some nice example/documentation for customizing button labels in a message box?

user2791379
  • 51
  • 1
  • 3

3 Answers3

10

Just in code solution:

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

enter image description here

pr0gg3r
  • 4,254
  • 1
  • 36
  • 27
5
  • Create your message box:

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

where this is your wpf form.

  • In your form that contains window:

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

With more setters, you can customize more using the xaml style.

Y P
  • 594
  • 8
  • 10
0
<Application.Resources>
    <ResourceDictionary>
          <!-- Here -->
    </ResourceDictionary>
</Application.Resources>

in Resource Dictionary add :

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

More info

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

Gonen09
  • 109
  • 1
  • 3