C# 材料设计wpf c中的MessageBox#

C# 材料设计wpf c中的MessageBox#,c#,wpf,xaml,material-design,material-design-in-xaml,C#,Wpf,Xaml,Material Design,Material Design In Xaml,我正在使用XAML工具包C#中的材质设计,在材质设计WPF C#中使用MessageBox 我需要这样或更好的MessageBox设计我在应用程序中开发了一个自定义MessageBox(使用材质设计控件)。 我将在下面向您展示WPF XAML和C#的代码。 它包含三种类型的消息框,如下所示 是的,不是 嗯 好的,取消 WPF XAML代码 标题 考虑使用具有以下额外好处的功能: 用于边框窗口、消息前景和背景、标题前景和背景、边框等的自定义样式 按钮将消息框详细信息复制到剪贴板 可滚

我正在使用XAML工具包C#中的材质设计,在材质设计WPF C#中使用MessageBox


我需要这样或更好的MessageBox设计我在应用程序中开发了一个自定义MessageBox(使用材质设计控件)。 我将在下面向您展示WPF XAML和C#的代码。 它包含三种类型的消息框,如下所示


  • 是的,不是


  • 好的,取消
  • WPF XAML代码

    标题 考虑使用具有以下额外好处的功能:

    • 用于边框窗口、消息前景和背景、标题前景和背景、边框等的自定义样式
    • 按钮将消息框详细信息复制到剪贴板
    • 可滚动消息框内容
    • 消息内容是可以承载任何内容的.NET UIElement

    可能有帮助:单击时确保标识符正确,并且您在dialogHost中。请检查上面添加ShowDialog()的代码。我现在得到了它,它的默认值可用于窗口类型,但我试图实现为UserControl,这对我帮助很大!
    <Window x:Class="EVotingDashBoard.MessageBoxCustom"
            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"
            mc:Ignorable="d"
            Title="MessageBoxWindow" Height="220" Width="500" 
            WindowStartupLocation="CenterScreen" WindowStyle="None" Background="White" 
            ResizeMode="CanResize" Topmost="True" ShowInTaskbar="False"
            xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
            TextElement.Foreground="{DynamicResource MaterialDesignBody}"
            TextElement.FontWeight="Regular"
            TextElement.FontSize="10"
            TextOptions.TextFormattingMode="Ideal"
            TextOptions.TextRenderingMode="Auto"        
            FontFamily="{DynamicResource MaterialDesignFont}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="197*"/>
                <ColumnDefinition Width="295*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <materialDesign:Card x:Name="cardHeader" Grid.Row="0" Padding="10" Margin="0" materialDesign:ShadowAssist.ShadowDepth="Depth5"   Background="{DynamicResource PrimaryHueDarkBrush}" Foreground="{DynamicResource PrimaryHueDarkForegroundBrush}" Visibility="Visible" Grid.ColumnSpan="2">
                <StackPanel>
                    <TextBlock x:Name="txtTitle" HorizontalAlignment="Center" VerticalAlignment="Stretch" Style="{DynamicResource MaterialDesignTitleTextBlock}" FontSize="20" >Message Title</TextBlock>
                </StackPanel>
            </materialDesign:Card>
            <StackPanel  HorizontalAlignment="Right" Margin="0,5,5,0"  VerticalAlignment="Top" Grid.Column="1">
                <Button x:Name="btnClose" Click="btnClose_Click" Width="35" Height="35"  Background="White" Foreground="{DynamicResource PrimaryHueDarkBrush}" Style="{StaticResource MaterialDesignFloatingActionDarkButton}">
                    <materialDesign:PackIcon Kind="Close" />
                </Button>
            </StackPanel>
            <Grid Grid.Row="1" Grid.ColumnSpan="2">
                <Grid Margin="20">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
    
                    <Grid Grid.Row="0">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
    
                        <materialDesign:TransitioningContent>
                            <materialDesign:TransitioningContent.OpeningEffects >
                                <materialDesign:TransitionEffect Kind="FadeIn" />
                                <materialDesign:TransitionEffect Kind="SlideInFromBottom" />
                            </materialDesign:TransitioningContent.OpeningEffects>
                            <TextBox x:Name="txtMessage" HorizontalAlignment="Center" IsReadOnly="True" Grid.Row="0" Margin="5" materialDesign:HintAssist.Hint="" FontSize="18" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
                        </materialDesign:TransitioningContent>
    
                    </Grid>
                    <Grid Grid.Row="1" Margin="0,20,0,5">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="auto"/>
                            <ColumnDefinition Width="auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
    
                        <Button x:Name="btnOk" Click="btnOk_Click" Grid.Column="1" Style="{StaticResource MaterialDesignRaisedButton}" Margin="5" Width="100" Content="OK" ToolTip="Ok"/>
                        <Button x:Name="btnCancel" Click="btnCancel_Click" Grid.Column="2" Style="{StaticResource MaterialDesignRaisedButton}" Margin="5" Width="100" Content="Cancel" ToolTip="Cancel"/>
                        <Button x:Name="btnYes" Click="btnYes_Click" Grid.Column="1" Style="{StaticResource MaterialDesignRaisedButton}" Margin="5" Width="100" Content="Yes" ToolTip="Yes"/>
                        <Button x:Name="btnNo" Click="btnNo_Click" Grid.Column="2" Style="{StaticResource MaterialDesignRaisedButton}" Margin="5" Width="100" Content="No" ToolTip="No"/>
                    </Grid>
    
                </Grid>
            </Grid>
        </Grid>
    </Window>
    
     /// <summary>
        /// Interaction logic for MessageBoxCustom.xaml
        /// </summary>
        public partial class MessageBoxCustom : Window
        {
            public MessageBoxCustom(string Message, MessageType Type, MessageButtons Buttons)
            {
                InitializeComponent();
                txtMessage.Text = Message;
                switch (Type)
                {
    
                    case MessageType.Info:
                        txtTitle.Text = "Info";
                        break;
                    case MessageType.Confirmation:
                        txtTitle.Text = "Confirmation";
                        break;
                    case MessageType.Success:
                        {
                            txtTitle.Text = "Success";
                        }
                        break;
                    case MessageType.Warning:
                        txtTitle.Text = "Warning";
                        break;
                    case MessageType.Error:
                        {   
                            txtTitle.Text = "Error";
                        }
                        break;
                }
                switch (Buttons)
                {
                    case MessageButtons.OkCancel:
                        btnYes.Visibility = Visibility.Collapsed; btnNo.Visibility = Visibility.Collapsed;
                        break;
                    case MessageButtons.YesNo:
                        btnOk.Visibility = Visibility.Collapsed; btnCancel.Visibility = Visibility.Collapsed;
                        break;
                    case MessageButtons.Ok:
                        btnOk.Visibility = Visibility.Visible;
                        btnCancel.Visibility = Visibility.Collapsed;
                        btnYes.Visibility = Visibility.Collapsed; btnNo.Visibility = Visibility.Collapsed;
                        break;
                }
            }
    
            private void btnYes_Click(object sender, RoutedEventArgs e)
            {
                this.DialogResult = true;
                this.Close();
            }
    
            private void btnCancel_Click(object sender, RoutedEventArgs e)
            {
                this.DialogResult = false;
                this.Close();
            }
    
            private void btnOk_Click(object sender, RoutedEventArgs e)
            {
                this.DialogResult = true;
                this.Close();
            }
    
            private void btnNo_Click(object sender, RoutedEventArgs e)
            {
                this.DialogResult = false;
                this.Close();
            }
    
            private void btnClose_Click(object sender, RoutedEventArgs e)
            {
                this.DialogResult = false;
                this.Close();
            }
        }
        public enum MessageType
        {
            Info,
            Confirmation,
            Success,
            Warning,
            Error,
        }
        public enum MessageButtons
        {
            OkCancel,
            YesNo,
            Ok,
        }
    
     private void Button_Close(object sender, RoutedEventArgs e)
     {
            bool? Result = new MessageBoxCustom("Are you sure, You want to close 
            application ?", MessageType.Confirmation, MessageButtons.YesNo).ShowDialog();
    
            if (Result.Value)
            {
                Application.Current.Shutdown();
            }
        }