• <em id="6vhwh"><rt id="6vhwh"></rt></em>

    <style id="6vhwh"></style>

    <style id="6vhwh"></style>
    1. <style id="6vhwh"></style>
        <sub id="6vhwh"><p id="6vhwh"></p></sub>
        <p id="6vhwh"></p>
          1. 国产亚洲欧洲av综合一区二区三区 ,色爱综合另类图片av,亚洲av免费成人在线,久久热在线视频精品视频,成在人线av无码免费,国产精品一区二区久久毛片,亚洲精品成人片在线观看精品字幕 ,久久亚洲精品成人av秋霞

            messageboxbuttons

            更新時間:2023-03-01 15:37:39 閱讀: 評論:0

            WPF 實現帶蒙版的 MessageBox 消息提示框

            作者:WPFDevelopersOrg

            原文鏈接: https://github.com/WPFDevelopersOrg/WPFDevelopers.Minimal

            框架使用大于等于.NET40;Visual Studio 2022;項目使用 MIT 開源許可協議;Nuget Install-Package WPFDevelopers.Minimal 3.2.6-preview

            MessageBox

            實現MessageBox的Show五種方法;Show(string messageBoxText) 傳入Msg參數;Show(string messageBoxText, string caption) 傳入Msg與標題參數;Show(string messageBoxText, string caption, MessageBoxButton button) 傳入Msg與標題、操作按鈕參數;Show(string messageBoxText, string caption, MessageBoxImage icon) 傳入Msg與標題、消息圖片參數;Show(string messageBoxText, string caption, MessageBoxButton button, MessageBoxImage icon) 傳入Msg與標題、操作按鈕、消息圖片參數;拿到父級Window窗體的內容Content,放入一個Grid里,再在容器里放入一個半透明的Grid,最后將整個Grid賦給父級Window窗體的內容Content;

            一、MessageBox.cs 代碼如下;

            using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows;using System.Windows.Controls;using System.Windows.Media;namespace WPFDevelopers.Minimal.Controls{ public static class MessageBox { public static MessageBoxResult Show(string messageBoxText) { var msg = new WPFMessageBox(messageBoxText); return GetWindow(msg); } public static MessageBoxResult Show(string messageBoxText, string caption) { var msg = new WPFMessageBox(messageBoxText, caption); return GetWindow(msg); } public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button) { var msg = new WPFMessageBox(messageBoxText, caption, button); return GetWindow(msg); } public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxImage icon) { var msg = new WPFMessageBox(messageBoxText, caption, icon); return GetWindow(msg); } public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button, MessageBoxImage icon) { var msg = new WPFMessageBox(messageBoxText, caption,button,icon); return GetWindow(msg); } static MessageBoxResult GetWindow(WPFMessageBox msg) { msg.WindowStartupLocation = WindowStartupLocation.CenterOwner; Window win = null; if (Application.Current.Windows.Count > 0) win = Application.Current.Windows.OfType<Window>().FirstOrDefault(o => o.IsActive); if (win != null) { var layer = new Grid() { Background = new SolidColorBrush(Color.FromArgb(128, 0, 0, 0)) }; UIElement original = win.Content as UIElement; win.Content = null; var container = new Grid(); container.Children.Add(original); container.Children.Add(layer); win.Content = container; msg.Owner = win; msg.ShowDialog(); container.Children.Clear(); win.Content = original; } el msg.Show(); return msg.Result; } }}

            二、Styles.MessageBox.xaml 代碼如下;

            <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/prentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;asmbly=mscorlib" xmlns:wpfsc="clr-namespace:WPFDevelopers.Minimal.Controls"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="../Themes/Basic/ControlBasic.xaml"/> <ResourceDictionary Source="../Themes/Basic/Animations.xaml"/> </ResourceDictionary.MergedDictionaries> <Style TargetType="{x:Type wpfsc:WPFMessageBox}"> <Setter Property="Foreground" Value="{DynamicResource PrimaryTextSolidColorBrush}" /> <Setter Property="Background" Value="{DynamicResource WhiteSolidColorBrush}" /> <Setter Property="BorderBrush" Value="{DynamicResource PrimaryNormalSolidColorBrush}" /> <Setter Property="SizeToContent" Value="WidthAndHeight" /> <Setter Property="ResizeMode" Value="NoResize" /> <Setter Property="ShowInTaskbar" Value="Fal" /> <Setter Property="SnapsToDevicePixels" Value="True"/> <Setter Property="ULayoutRounding" Value="True" /> <Setter Property="TextOptions.TextFormattingMode" Value="Display" /> <Setter Property="TextOptions.TextRenderingMode" Value="ClearType" /> <Setter Property="WindowStyle" Value="None" /> <Setter Property="FontFamily" Value="{DynamicResource NormalFontFamily}" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type wpfsc:WPFMessageBox}"> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> <Grid> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition /> <RowDefinition/> </Grid.RowDefinitions> <Grid Grid.Row="0"> <DockPanel Margin="20,0,0,0"> <TextBlock x:Name="PART_Title" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="{DynamicResource TitleFontSize}" Foreground="{DynamicResource PrimaryTextSolidColorBrush}"/> <Button Name="PART_CloButton" Margin="0,6" ToolTip="Clo" HorizontalAlignment="Right" IsTabStop="Fal" Style="{DynamicResource WindowButtonStyle}"> <Path Width="10" Height="10" HorizontalAlignment="Center" VerticalAlignment="Center" Data="{DynamicResource PathMetroWindowClo}" Fill="{DynamicResource PrimaryTextSolidColorBrush}" Stretch="Fill" /> </Button> </DockPanel> </Grid> <Grid Grid.Row="1" Margin="20"> <DockPanel> <Path x:Name="PART_Path" Data="{DynamicResource PathInformation}" Fill="{DynamicResource PrimaryNormalSolidColorBrush}" Height="25" Width="25" Stretch="Fill"></Path> <TextBlock x:Name="PART_Message" TextWrapping="Wrap" MaxWidth="500" Width="Auto" VerticalAlignment="Center" FontSize="{DynamicResource NormalFontSize}" Padding="10,0" Foreground="{DynamicResource RegularTextSolidColorBrush}"/> </DockPanel> </Grid> <Grid Grid.Row="2" Margin="140,20,10,10"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Right"> <Button x:Name="PART_ButtonCancel" Content="取消" Visibility="Collapd"/> <Button x:Name="PART_ButtonOK" Style="{DynamicResource PrimaryButton}" Margin="10,0,0,0" Content="確認"/> </StackPanel> </Grid> </Grid> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style></ResourceDictionary>

            三、WPFMessageBox.cs 代碼如下;

            using System;using System.Collections.Generic;using System.ComponentModel;using System.Text;using System.Windows;using System.Windows.Controls;using System.Windows.Media;using System.Windows.Shapes;namespace WPFDevelopers.Minimal.Controls{ [TemplatePart(Name = TitleTemplateName, Type = typeof(TextBlock))] [TemplatePart(Name = CloButtonTemplateName, Type = typeof(Button))] [TemplatePart(Name = MessageTemplateName, Type = typeof(TextBlock))] [TemplatePart(Name = ButtonCancelTemplateName, Type = typeof(Button))] [TemplatePart(Name = ButtonCancelTemplateName, Type = typeof(Button))] [TemplatePart(Name = PathTemplateName, Type = typeof(Path))] public aled class WPFMessageBox : Window { private const string TitleTemplateName = "PART_Title"; private const string CloButtonTemplateName = "PART_CloButton"; private const string MessageTemplateName = "PART_Message"; private const string ButtonCancelTemplateName = "PART_ButtonCancel"; private const string ButtonOKTemplateName = "PART_ButtonOK"; private const string PathTemplateName = "PART_Path"; private string _messageString; private string _titleString; private Geometry _geometry; private SolidColorBrush _solidColorBrush; private Visibility _cancelVisibility = Visibility.Collapd; private Visibility _okVisibility; private TextBlock _title; private TextBlock _message; private Button _cloButton; private Button _buttonCancel; private Button _buttonOK; private Path _path; static WPFMessageBox() { DefaultStyleKeyProperty.OverrideMetadata(typeof(WPFMessageBox), new FrameworkPropertyMetadata(typeof(WPFMessageBox))); } public override void OnApplyTemplate() { ba.OnApplyTemplate(); _title = GetTemplateChild(TitleTemplateName) as TextBlock; _message = GetTemplateChild(MessageTemplateName) as TextBlock; if (_title == null || _message == null) throw new InvalidOperationException("the title or message control is null!"); _title.Text = _titleString; _message.Text = _messageString; _path = GetTemplateChild(PathTemplateName) as Path; if (_path != null) { _path.Data = _geometry; _path.Fill = _solidColorBrush; } _cloButton = GetTemplateChild(CloButtonTemplateName) as Button; if (_cloButton != null) _cloButton.Click += _cloButton_Click; _buttonCancel = GetTemplateChild(ButtonCancelTemplateName) as Button; if (_buttonCancel != null) { _buttonCancel.Visibility = _cancelVisibility; _buttonCancel.Click += _buttonCancel_Click; } _buttonOK = GetTemplateChild(ButtonOKTemplateName) as Button; if (_buttonOK != null) { _buttonOK.Visibility = _okVisibility; _buttonOK.Click += _buttonOK_Click; } if (Owner == null) { BorderThickness = new Thickness(1); WindowStartupLocation = WindowStartupLocation.CenterScreen; } } private void _buttonOK_Click(object nder, RoutedEventArgs e) { Result = MessageBoxResult.OK; Clo(); } private void _buttonCancel_Click(object nder, RoutedEventArgs e) { Result = MessageBoxResult.Cancel; Clo(); } private void _cloButton_Click(object nder, RoutedEventArgs e) { Clo(); } protected override void OnClod(EventArgs e) { ba.OnClod(e); if (Owner == null) return; var grid = Owner.Content as Grid; UIElement original = VisualTreeHelper.GetChild(grid, 0) as UIElement; grid.Children.Remove(original); Owner.Content = original; } public MessageBoxResult Result { get; t; } public WPFMessageBox(string message) { _messageString = message; } public WPFMessageBox(string message, string caption) { _titleString = caption; _messageString = message; } public WPFMessageBox(string message, string caption, MessageBoxButton button) { _titleString = caption; _messageString = message; ; } public WPFMessageBox(string message, string caption, MessageBoxImage image) { _titleString = caption; _messageString = message; DisplayImage(image); } public WPFMessageBox(string message, string caption, MessageBoxButton button, MessageBoxImage image) { _titleString = caption; _messageString = message; DisplayImage(image); DisplayButtons(button); } private void DisplayButtons(MessageBoxButton button) { switch (button) { ca MessageBoxButton.OKCancel: ca MessageBoxButton.YesNo: _cancelVisibility = Visibility.Visible; _okVisibility = Visibility.Visible; break; //ca MessageBoxButton.YesNoCancel: // break; default: _okVisibility = Visibility.Visible; break; } } private void DisplayImage(MessageBoxImage image) { switch (image) { ca MessageBoxImage.Warning: _geometry = Application.Current.Resources["PathWarning"] as Geometry; _solidColorBrush = Application.Current.Resources["WarningSolidColorBrush"] as SolidColorBrush; break; ca MessageBoxImage.Error: _geometry = Application.Current.Resources["PathError"] as Geometry; _solidColorBrush = Application.Current.Resources["DangerSolidColorBrush"] as SolidColorBrush; break; ca MessageBoxImage.Information: _geometry = Application.Current.Resources["PathWarning"] as Geometry; _solidColorBrush = Application.Current.Resources["SuccessSolidColorBrush"] as SolidColorBrush; break; ca MessageBoxImage.Question: _geometry = Application.Current.Resources["PathQuestion"] as Geometry; _solidColorBrush = Application.Current.Resources["PrimaryNormalSolidColorBrush"] as SolidColorBrush; break; default: break; } } }}

            Nuget Install-Package WPFDevelopers.Minimal

            本文發布于:2023-02-28 20:07:00,感謝您對本站的認可!

            本文鏈接:http://www.newhan.cn/zhishi/a/167765625976486.html

            版權聲明:本站內容均來自互聯網,僅供演示用,請勿用于商業和其他非法用途。如果侵犯了您的權益請與我們聯系,我們將在24小時內刪除。

            本文word下載地址:messageboxbuttons.doc

            本文 PDF 下載地址:messageboxbuttons.pdf

            相關文章
            留言與評論(共有 0 條評論)
               
            驗證碼:
            Copyright ?2019-2022 Comsenz Inc.Powered by ? 實用文體寫作網旗下知識大全大全欄目是一個全百科類寶庫! 優秀范文|法律文書|專利查詢|
            主站蜘蛛池模板: 久久精品日日躁夜夜躁| 国产va免费精品观看| 肉多荤文高h羞耻玩弄校园| 国产综合视频精品一区二区 | 四虎在线播放亚洲成人| 亚洲综合在线亚洲优优色| 蜜芽久久人人超碰爱香蕉| 久久天天躁夜夜躁一区| 少妇又紧又色又爽又刺激视频| 1精品啪国产在线观看免费牛牛| 亚洲综合一区国产精品| 天堂va亚洲va欧美va国产| 精品国产自在现线看久久| 无码精油按摩潮喷在线播放| 国产精品一国产精品亚洲| 在国产线视频A在线视频| 国产a级三级三级三级| 中文字幕在线观看一区二区| 亚洲另类国产欧美一区二区| 日本一区二区三区黄色| 双乳奶水饱满少妇呻吟免费看| 97人妻免费碰视频碰免| 国产一级特黄性生活大片| 国产精品午夜福利合集| 人人超人人超碰超国产| 丰满少妇在线观看网站| 三上悠亚ssⅰn939无码播放| 99re免费视频| 国产麻豆精品手机在线观看| 国产精品日韩中文字幕熟女 | 日韩精品 在线一区二区| 国产精品福利自产拍在线观看| 国产精品久久无码不卡黑寡妇| 亚洲中文精品人人永久免费| 免费无码一区无码东京热| 香蕉乱码成人久久天堂爱| 男同精品视频免费观看网站| 人妻熟女一区| 狠狠v日韩v欧美v| 国产中文字幕精品视频| 亚洲精品天堂在线观看|