The standard style does not fit into my design, and all validation goes through Messagebox.Show("Сообщение") . Where to change the style? And it is necessary to change the functionality, like a regular window, since I made the transparent style of the main windows and use stylized elements ...

    1 answer 1

    No MessageBox - system, it does not stylize.

    Use samopisny MessageBox , the benefit there is not much to write.

    Here is an example:

    XAML:

     <Window x:Class="Test.MessageBox" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:Test" mc:Ignorable="d" Title="Message Box" Height="200" Width="300"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <TextBlock Name="MessageContainer" TextWrapping="WrapWithOverflow" Margin="10"/> <StackPanel Name="ButtonContainer" Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right" Margin="10"> <StackPanel.Resources> <Style TargetType="Button"> <Setter Property="MinHeight" Value="25"/> <Setter Property="MinWidth" Value="75"/> <Setter Property="Margin" Value="10,0,0,0"/> </Style> </StackPanel.Resources> </StackPanel> </Grid> </Window> 

    Code-behind:

     public partial class MessageBox : Window { public MessageBox() { InitializeComponent(); } void AddButtons(MessageBoxButton buttons) { switch (buttons) { case MessageBoxButton.OK: AddButton("OK", MessageBoxResult.OK); break; case MessageBoxButton.OKCancel: AddButton("OK", MessageBoxResult.OK); AddButton("Cancel", MessageBoxResult.Cancel, isCancel: true); break; case MessageBoxButton.YesNo: AddButton("Yes", MessageBoxResult.Yes); AddButton("No", MessageBoxResult.No); break; case MessageBoxButton.YesNoCancel: AddButton("Yes", MessageBoxResult.Yes); AddButton("No", MessageBoxResult.No); AddButton("Cancel", MessageBoxResult.Cancel, isCancel: true); break; default: throw new ArgumentException("Unknown button value", "buttons"); } } void AddButton(string text, MessageBoxResult result, bool isCancel = false) { var button = new Button() { Content = text, IsCancel = isCancel }; button.Click += (o, args) => { Result = result; DialogResult = true; }; ButtonContainer.Children.Add(button); } MessageBoxResult Result = MessageBoxResult.None; public static MessageBoxResult Show(string caption, string message, MessageBoxButton buttons) { var dialog = new MessageBox() { Title = caption }; dialog.MessageContainer.Text = message; dialog.AddButtons(buttons); dialog.ShowDialog(); return dialog.Result; } } 

    As a result, you get a normal window, and you can stylize it as you like.

    house managers


    You will have to solve the problems with localization, with resizing the window (it is not necessary to give the user the opportunity to maximize the window), etc.

    • the logic is clear, thank you) - Awesome7997
    • @ Awesome7997: Please! - VladD