C #: advanced WPF toolkit - Customixing button shortcuts in MessageBox

I would like to implement a message box in my wpf project. Text: "Select language:" Alternatives are English (OK) and German (Cancel).

In this context, I am trying to customize buttons in a MessageBox. To do this, I am trying to implement the advanced WPF toolkit, but I have problems understanding the documentation for the advanced WPF toolkit.

My code looks 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 there any other suitable controls used where the user of the wpf application can choose between alternatives?

2) Where can I find a good example / documentation for customizing button shortcuts in a message box?

+4
source share
3 answers

Just in solving the code:

 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

+6
source
  • Create a 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 containing the 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 a lot of settings, you can customize more using the xaml style.

+3
source
 <Application.Resources> <ResourceDictionary> <!-- Here --> </ResourceDictionary> </Application.Resources> 

in the add resource dictionary:

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

Additional Information

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

0
source

Source: https://habr.com/ru/post/1502801/


All Articles