├── .gitattributes
├── .gitignore
├── DemoProj
├── App.config
├── App.xaml
├── App.xaml.cs
├── DemoProj.csproj
├── MainWindow.xaml
├── MainWindow.xaml.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
└── packages.config
├── LICENSE
├── ModernMessageBoxLib.sln
├── ModernMessageBoxLib.sln.DotSettings
├── ModernMessageBoxLib
├── Helper
│ ├── UnSafeWin32NativeMethods.cs
│ └── WindowBlurBackgroundHelper.cs
├── IndeterminateProgressWindow.xaml
├── IndeterminateProgressWindow.xaml.cs
├── ModernMessageBox.xaml
├── ModernMessageBox.xaml.cs
├── ModernMessageBoxLib.csproj
├── ModernMessageBoxLib.nuspec
├── ModernMessageboxButtonStatus.cs
├── ModernMessageboxButtonStatusConverter.cs
├── ModernMessageboxIcons.cs
├── ModernMessageboxResult.cs
├── ProcessRing.xaml
├── ProcessRing.xaml.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── QModernMessageBox.cs
├── Themes
│ └── ModernButtons.xaml
└── packages.config
├── readme.md
└── web
├── sc1.png
├── sc2.png
├── sc3.png
└── sc4.png
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # NCrunch
114 | _NCrunch_*
115 | .*crunch*.local.xml
116 | nCrunchTemp_*
117 |
118 | # MightyMoose
119 | *.mm.*
120 | AutoTest.Net/
121 |
122 | # Web workbench (sass)
123 | .sass-cache/
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.[Pp]ublish.xml
143 | *.azurePubxml
144 | # TODO: Comment the next line if you want to checkin your web deploy settings
145 | # but database connection strings (with potential passwords) will be unencrypted
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
150 | # checkin your Azure Web App publish settings, but sensitive information contained
151 | # in these scripts will be unencrypted
152 | PublishScripts/
153 |
154 | # NuGet Packages
155 | *.nupkg
156 | # The packages folder can be ignored because of Package Restore
157 | **/packages/*
158 | # except build/, which is used as an MSBuild target.
159 | !**/packages/build/
160 | # Uncomment if necessary however generally it will be regenerated when needed
161 | #!**/packages/repositories.config
162 | # NuGet v3's project.json files produces more ignoreable files
163 | *.nuget.props
164 | *.nuget.targets
165 |
166 | # Microsoft Azure Build Output
167 | csx/
168 | *.build.csdef
169 |
170 | # Microsoft Azure Emulator
171 | ecf/
172 | rcf/
173 |
174 | # Windows Store app package directories and files
175 | AppPackages/
176 | BundleArtifacts/
177 | Package.StoreAssociation.xml
178 | _pkginfo.txt
179 |
180 | # Visual Studio cache files
181 | # files ending in .cache can be ignored
182 | *.[Cc]ache
183 | # but keep track of directories ending in .cache
184 | !*.[Cc]ache/
185 |
186 | # Others
187 | ClientBin/
188 | ~$*
189 | *~
190 | *.dbmdl
191 | *.dbproj.schemaview
192 | *.jfm
193 | *.pfx
194 | *.publishsettings
195 | node_modules/
196 | orleans.codegen.cs
197 |
198 | # Since there are multiple workflows, uncomment next line to ignore bower_components
199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200 | #bower_components/
201 |
202 | # RIA/Silverlight projects
203 | Generated_Code/
204 |
205 | # Backup & report files from converting an old project file
206 | # to a newer Visual Studio version. Backup files are not needed,
207 | # because we have git ;-)
208 | _UpgradeReport_Files/
209 | Backup*/
210 | UpgradeLog*.XML
211 | UpgradeLog*.htm
212 |
213 | # SQL Server files
214 | *.mdf
215 | *.ldf
216 |
217 | # Business Intelligence projects
218 | *.rdl.data
219 | *.bim.layout
220 | *.bim_*.settings
221 |
222 | # Microsoft Fakes
223 | FakesAssemblies/
224 |
225 | # GhostDoc plugin setting file
226 | *.GhostDoc.xml
227 |
228 | # Node.js Tools for Visual Studio
229 | .ntvs_analysis.dat
230 |
231 | # Visual Studio 6 build log
232 | *.plg
233 |
234 | # Visual Studio 6 workspace options file
235 | *.opt
236 |
237 | # Visual Studio LightSwitch build output
238 | **/*.HTMLClient/GeneratedArtifacts
239 | **/*.DesktopClient/GeneratedArtifacts
240 | **/*.DesktopClient/ModelManifest.xml
241 | **/*.Server/GeneratedArtifacts
242 | **/*.Server/ModelManifest.xml
243 | _Pvt_Extensions
244 |
245 | # Paket dependency manager
246 | .paket/paket.exe
247 | paket-files/
248 |
249 | # FAKE - F# Make
250 | .fake/
251 |
252 | # JetBrains Rider
253 | .idea/
254 | *.sln.iml
255 |
256 | # CodeRush
257 | .cr/
258 |
259 | # Python Tools for Visual Studio (PTVS)
260 | __pycache__/
261 | *.pyc
--------------------------------------------------------------------------------
/DemoProj/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/DemoProj/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/DemoProj/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 | using ModernMessageBoxLib;
9 |
10 | namespace DemoProj
11 | {
12 | ///
13 | /// App.xaml 的交互逻辑
14 | ///
15 | public partial class App : Application
16 | { }
17 | }
18 |
--------------------------------------------------------------------------------
/DemoProj/DemoProj.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {7F7B8E94-9401-422E-8B2C-CD0B0975B794}
8 | WinExe
9 | DemoProj
10 | DemoProj
11 | v4.5.2
12 | 512
13 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
14 | 4
15 | true
16 |
17 |
18 |
19 | AnyCPU
20 | true
21 | full
22 | false
23 | bin\Debug\
24 | DEBUG;TRACE
25 | prompt
26 | 4
27 |
28 |
29 | AnyCPU
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | 4.0
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | MSBuild:Compile
57 | Designer
58 |
59 |
60 | MSBuild:Compile
61 | Designer
62 |
63 |
64 | App.xaml
65 | Code
66 |
67 |
68 | MainWindow.xaml
69 | Code
70 |
71 |
72 |
73 |
74 | Code
75 |
76 |
77 | True
78 | True
79 | Resources.resx
80 |
81 |
82 | True
83 | Settings.settings
84 | True
85 |
86 |
87 | ResXFileCodeGenerator
88 | Resources.Designer.cs
89 |
90 |
91 |
92 | SettingsSingleFileGenerator
93 | Settings.Designer.cs
94 |
95 |
96 |
97 |
98 | Designer
99 |
100 |
101 |
102 |
103 | {ba88d9e1-3978-4092-ae72-9a82baf65f15}
104 | ModernMessageBoxLib
105 |
106 |
107 |
108 |
--------------------------------------------------------------------------------
/DemoProj/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/DemoProj/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using System.Windows;
3 | using System.Windows.Forms;
4 | using System.Windows.Input;
5 | using System.Windows.Media;
6 | using ModernMessageBoxLib;
7 | using MessageBox = System.Windows.MessageBox;
8 |
9 | namespace DemoProj
10 | {
11 | ///
12 | /// MainWindow.xaml 的交互逻辑
13 | ///
14 | public partial class MainWindow : Window
15 | {
16 | private bool _secondTheme = false;
17 |
18 | public MainWindow()
19 | {
20 | InitializeComponent();
21 | QModernMessageBox.MainLang = new QMetroMessageLang() {
22 | Ok = "确定",
23 | Cancel = "取消",
24 | Abort = "中止(A)",
25 | Ignore = "忽略(I)",
26 | No = "否(N)",
27 | Yes = "是(Y)",
28 | Retry = "重试(R)"
29 | };
30 | IndeterminateProgressWindow.GlobalBackground = QModernMessageBox.GlobalBackground = new SolidColorBrush(Colors.White){Opacity = 0.6};
31 | IndeterminateProgressWindow.GlobalForeground = QModernMessageBox.GlobalForeground = Brushes.Black;
32 |
33 | }
34 |
35 | private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
36 | {
37 | var msg = new ModernMessageBox("The quick brown fox jumps over the lazy dog.\n", "hello world", ModernMessageboxIcons.Info, "CSharp", "Java",
38 | "Python") {
39 | Button1Key = Key.D1,
40 | Button2Key = Key.D2,
41 | Button3Key = Key.D3,
42 | CheckboxText = "Don't show this again",
43 | CheckboxVisibility = Visibility.Visible,
44 | TextBoxText = "some staff",
45 | TextBoxVisibility = Visibility.Visible,
46 | };
47 |
48 | msg.ShowDialog();
49 | QModernMessageBox.None(msg.TextBoxText,"TextBoxText");
50 | QModernMessageBox.None(msg.CheckboxChecked.ToString(),"CheckboxChecked");
51 |
52 | }
53 |
54 | private void ButtonBase_OnClick_1(object sender, RoutedEventArgs e)
55 | {
56 | QModernMessageBox.Show("The quick brown fox jumps over the lazy dog.", "hello world", QModernMessageBox.QModernMessageBoxButtons.YesNoCancel,
57 | ModernMessageboxIcons.Error);
58 | }
59 |
60 | private void ButtonBase_OnClick_2(object sender, RoutedEventArgs e)
61 | {
62 | _secondTheme = !_secondTheme;
63 | if (_secondTheme) {
64 | IndeterminateProgressWindow.GlobalBackground = QModernMessageBox.GlobalBackground = new SolidColorBrush(Colors.Black) { Opacity = 0.6 };
65 | IndeterminateProgressWindow.GlobalForeground = QModernMessageBox.GlobalForeground = Brushes.White;
66 | }
67 | else {
68 | IndeterminateProgressWindow.GlobalBackground = QModernMessageBox.GlobalBackground = new SolidColorBrush(Colors.White) { Opacity = 0.6 };
69 | IndeterminateProgressWindow.GlobalForeground = QModernMessageBox.GlobalForeground = Brushes.Black;
70 | }
71 | }
72 |
73 | private async void ButtonBase_OnClick_3(object sender, RoutedEventArgs e)
74 | {
75 | var win = new IndeterminateProgressWindow("Please wait while we are installing the virus into your computer. . .");
76 | win.Show();
77 | //Do Some Staff
78 | await Task.Delay(5000);
79 | //Change the message the 2nd time
80 | win.Message = "Done!!!";
81 | win.Close();
82 |
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/DemoProj/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // 有关程序集的一般信息由以下
8 | // 控制。更改这些特性值可修改
9 | // 与程序集关联的信息。
10 | [assembly: AssemblyTitle("DemoProj")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("DemoProj")]
15 | [assembly: AssemblyCopyright("Copyright © 2018")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // 将 ComVisible 设置为 false 会使此程序集中的类型
20 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
21 | //请将此类型的 ComVisible 特性设置为 true。
22 | [assembly: ComVisible(false)]
23 |
24 | //若要开始生成可本地化的应用程序,请设置
25 | //.csproj 文件中的 CultureYouAreCodingWith
26 | //例如,如果您在源文件中使用的是美国英语,
27 | //使用的是美国英语,请将 设置为 en-US。 然后取消
28 | //对以下 NeutralResourceLanguage 特性的注释。 更新
29 | //以下行中的“en-US”以匹配项目文件中的 UICulture 设置。
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //主题特定资源词典所处位置
36 | //(未在页面中找到资源时使用,
37 | //或应用程序资源字典中找到时使用)
38 | ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
39 | //(未在页面中找到资源时使用,
40 | //、应用程序或任何主题专用资源字典中找到时使用)
41 | )]
42 |
43 |
44 | // 程序集的版本信息由下列四个值组成:
45 | //
46 | // 主版本
47 | // 次版本
48 | // 生成号
49 | // 修订号
50 | //
51 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
52 | // 方法是按如下所示使用“*”: :
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/DemoProj/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.42000
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace DemoProj.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// 一个强类型的资源类,用于查找本地化的字符串等。
17 | ///
18 | // 此类是由 StronglyTypedResourceBuilder
19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
21 | // (以 /str 作为命令选项),或重新生成 VS 项目。
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// 返回此类使用的缓存的 ResourceManager 实例。
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DemoProj.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// 重写当前线程的 CurrentUICulture 属性
51 | /// 重写当前线程的 CurrentUICulture 属性。
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/DemoProj/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/DemoProj/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.42000
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace DemoProj.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.8.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/DemoProj/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/DemoProj/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 SakuraTrak Studio
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/ModernMessageBoxLib.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27703.2042
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModernMessageBoxLib", "ModernMessageBoxLib\ModernMessageBoxLib.csproj", "{BA88D9E1-3978-4092-AE72-9A82BAF65F15}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DemoProj", "DemoProj\DemoProj.csproj", "{7F7B8E94-9401-422E-8B2C-CD0B0975B794}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {BA88D9E1-3978-4092-AE72-9A82BAF65F15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {BA88D9E1-3978-4092-AE72-9A82BAF65F15}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {BA88D9E1-3978-4092-AE72-9A82BAF65F15}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {BA88D9E1-3978-4092-AE72-9A82BAF65F15}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {7F7B8E94-9401-422E-8B2C-CD0B0975B794}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {7F7B8E94-9401-422E-8B2C-CD0B0975B794}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {7F7B8E94-9401-422E-8B2C-CD0B0975B794}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {7F7B8E94-9401-422E-8B2C-CD0B0975B794}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {0183B76F-7A7D-46F9-9A10-ED3615F223D3}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/ModernMessageBoxLib.sln.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | HINT
--------------------------------------------------------------------------------
/ModernMessageBoxLib/Helper/UnSafeWin32NativeMethods.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace ModernMessageBoxLib.Helper
5 | {
6 |
7 | internal static class UnSafeWin32NativeMethods
8 | {
9 | [DllImport("user32.dll")]
10 | internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data);
11 |
12 | internal enum AccentState
13 | {
14 | AccentDisabled = 1,
15 | AccentEnableGradient = 0,
16 | AccentEnableTransparentgradient = 2,
17 | AccentEnableBlurbehind = 3,
18 | AccentInvalidState = 4
19 | }
20 |
21 | [StructLayout(LayoutKind.Sequential)]
22 | internal struct AccentPolicy
23 | {
24 | public AccentState AccentState;
25 | // ReSharper disable FieldCanBeMadeReadOnly.Global
26 | public int AccentFlags;
27 | public int GradientColor;
28 | public int AnimationId;
29 | // ReSharper restore FieldCanBeMadeReadOnly.Global
30 | }
31 |
32 | [StructLayout(LayoutKind.Sequential)]
33 | internal struct WindowCompositionAttributeData
34 | {
35 | public WindowCompositionAttribute Attribute;
36 | public IntPtr Data;
37 | public int SizeOfData;
38 | }
39 |
40 | internal enum WindowCompositionAttribute
41 | {
42 | // ...
43 | WcaAccentPolicy = 19
44 | // ...
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/ModernMessageBoxLib/Helper/WindowBlurBackgroundHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 | using System.Windows;
4 | using System.Windows.Interop;
5 |
6 | namespace ModernMessageBoxLib.Helper
7 | {
8 | internal static class WindowBlurBackgroundHelper
9 | {
10 |
11 | internal static bool BlurWindow(Window win)
12 | {
13 | if (Environment.OSVersion.Version.Major < 10 && Environment.OSVersion.Version.Minor < 2) {
14 | return false;
15 | }
16 |
17 | try {
18 | var winhelp = new WindowInteropHelper(win);
19 | var accent = new UnSafeWin32NativeMethods.AccentPolicy {
20 | AccentState = UnSafeWin32NativeMethods.AccentState.AccentEnableBlurbehind
21 | };
22 | var accentStructSize = Marshal.SizeOf(accent);
23 |
24 | var accentPtr = Marshal.AllocHGlobal(accentStructSize);
25 | Marshal.StructureToPtr(accent, accentPtr, false);
26 |
27 | var data = new UnSafeWin32NativeMethods.WindowCompositionAttributeData {
28 | Attribute = UnSafeWin32NativeMethods.WindowCompositionAttribute.WcaAccentPolicy,
29 | SizeOfData = accentStructSize,
30 | Data = accentPtr
31 | };
32 |
33 | UnSafeWin32NativeMethods.SetWindowCompositionAttribute(winhelp.Handle, ref data);
34 |
35 | Marshal.FreeHGlobal(accentPtr);
36 | return true;
37 | }
38 | catch {
39 | return false;
40 | }
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/ModernMessageBoxLib/IndeterminateProgressWindow.xaml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
35 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/ModernMessageBoxLib/IndeterminateProgressWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows;
3 | using System.Windows.Media.Animation;
4 | using System.ComponentModel;
5 | using System.Windows.Media;
6 |
7 | namespace ModernMessageBoxLib
8 | {
9 | ///
10 | /// A window to notice user the progress.
11 | ///
12 | public partial class IndeterminateProgressWindow
13 | {
14 | ///
15 | /// Get or set the default background of IndeterminateProgressWindow.
16 | /// Transparent is allowed.
17 | ///
18 | public static Brush GlobalBackground { get; set; } = new SolidColorBrush(Colors.Black) { Opacity = 0.6 };
19 | ///
20 | /// Get or set the default foreground of IndeterminateProgressWindow
21 | ///
22 | public static Brush GlobalForeground { get; set; } = Brushes.White;
23 | ///
24 | /// Get or set the element to show at the IndeterminateProgressWindow.
25 | ///
26 | public static readonly DependencyProperty MessageProperty = DependencyProperty.Register("Message",
27 | typeof(object), typeof(IndeterminateProgressWindow), new PropertyMetadata(default(object)));
28 | ///
29 | /// Get or set the CornerRadius of the background border.
30 | ///
31 | public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(IndeterminateProgressWindow), new PropertyMetadata(new CornerRadius(5)));
32 |
33 | ///
34 | /// Get or set the element to show at the IndeterminateProgressWindow.
35 | ///
36 | public object Message
37 | {
38 | get => GetValue(MessageProperty);
39 | set => SetValue(MessageProperty, value);
40 | }
41 |
42 | ///
43 | /// Get or set the CornerRadius of the background border.
44 | ///
45 | public CornerRadius CornerRadius
46 | {
47 | get => (CornerRadius)GetValue(CornerRadiusProperty);
48 | set => SetValue(CornerRadiusProperty, value);
49 | }
50 |
51 | private bool _sbComplete;
52 |
53 | ///
54 | /// Create an object of IndeterminateProgressWindow.
55 | ///
56 | public IndeterminateProgressWindow()
57 | {
58 | InitializeComponent();
59 | Background = GlobalBackground;
60 | Foreground = GlobalForeground;
61 | }
62 |
63 | ///
64 | /// Create and init an object of IndeterminateProgressWindow.
65 | ///
66 | /// the element to show at the IndeterminateProgressWindow
67 | public IndeterminateProgressWindow(object message)
68 | {
69 | InitializeComponent();
70 | Background = GlobalBackground;
71 | Foreground = GlobalForeground;
72 | Message = message;
73 | }
74 |
75 | private void Window_Closing(object sender, CancelEventArgs e)
76 | {
77 | if (!_sbComplete) {
78 | e.Cancel = true;
79 | var sb = Resources["CloseStory"] as Storyboard;
80 | // ReSharper disable once PossibleNullReferenceException
81 | sb.Begin();
82 | }
83 | else {
84 | e.Cancel = false;
85 | }
86 | }
87 |
88 | private void Storyboard_Completed(object sender, EventArgs e)
89 | {
90 | _sbComplete = true;
91 | Close();
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/ModernMessageBoxLib/ModernMessageBox.xaml:
--------------------------------------------------------------------------------
1 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
32 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
55 |
62 |
69 |
70 |
71 |
76 |
82 |
90 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/ModernMessageBoxLib/ModernMessageBox.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 | using System.Media;
4 | using System.Threading.Tasks;
5 | using System.Windows;
6 | using System.Windows.Input;
7 | using System.Windows.Media;
8 | using ModernMessageBoxLib.Helper;
9 |
10 | namespace ModernMessageBoxLib
11 | {
12 | ///
13 | /// Display a MessageBox with a Modern Style
14 | ///
15 | public partial class ModernMessageBox
16 | {
17 | #region Fields
18 |
19 | private bool _enableKey;
20 |
21 | #endregion
22 | #region DependencyProperty
23 |
24 | ///
25 | /// The display content of Button1
26 | ///
27 | public static readonly DependencyProperty Button1TextProperty = DependencyProperty.Register("Button1Text",
28 | typeof(string), typeof(ModernMessageBox), new PropertyMetadata("Button1"));
29 |
30 | ///
31 | /// The display content of Button1
32 | ///
33 | public string Button1Text
34 | {
35 | get => (string)GetValue(Button1TextProperty);
36 | set => SetValue(Button1TextProperty, value);
37 | }
38 |
39 | ///
40 | /// The status of Button1(IsEnabled and Visibility)
41 | ///
42 | public static readonly DependencyProperty Button1StatusProperty = DependencyProperty.Register("Button1Status",
43 | typeof(ModernMessageboxButtonStatus), typeof(ModernMessageBox),
44 | new PropertyMetadata(ModernMessageboxButtonStatus.Normal));
45 |
46 | ///
47 | /// The status of Button1(IsEnabled and Visibility)
48 | ///
49 | public ModernMessageboxButtonStatus Button1Status
50 | {
51 | get => (ModernMessageboxButtonStatus)GetValue(Button1StatusProperty);
52 | set => SetValue(Button1StatusProperty, value);
53 | }
54 |
55 | ///
56 | /// The display content of Button2
57 | ///
58 | public static readonly DependencyProperty Button2TextProperty = DependencyProperty.Register("Button2Text",
59 | typeof(string), typeof(ModernMessageBox), new PropertyMetadata("Button2"));
60 |
61 | ///
62 | /// The display content of Button2
63 | ///
64 | public string Button2Text
65 | {
66 | get => (string)GetValue(Button2TextProperty);
67 | set => SetValue(Button2TextProperty, value);
68 | }
69 |
70 | ///
71 | /// The status of Button2(IsEnabled and Visibility)
72 | ///
73 | public static readonly DependencyProperty Button2StatusProperty = DependencyProperty.Register("Button2Status",
74 | typeof(ModernMessageboxButtonStatus), typeof(ModernMessageBox),
75 | new PropertyMetadata(ModernMessageboxButtonStatus.Invisibled));
76 |
77 | ///
78 | /// The status of Button2(IsEnabled and Visibility)
79 | ///
80 | public ModernMessageboxButtonStatus Button2Status
81 | {
82 | get => (ModernMessageboxButtonStatus)GetValue(Button2StatusProperty);
83 | set => SetValue(Button2StatusProperty, value);
84 | }
85 |
86 | ///
87 | /// The display content of Button3
88 | ///
89 | public static readonly DependencyProperty Button3TextProperty = DependencyProperty.Register("Button3Text",
90 | typeof(string), typeof(ModernMessageBox), new PropertyMetadata("Button3"));
91 |
92 | ///
93 | /// The display content of Button3
94 | ///
95 | public string Button3Text
96 | {
97 | get => (string)GetValue(Button3TextProperty);
98 | set => SetValue(Button3TextProperty, value);
99 | }
100 |
101 | ///
102 | /// The status of Button3(IsEnabled and Visibility)
103 | ///
104 | public static readonly DependencyProperty Button3StatusProperty = DependencyProperty.Register("Button3Status",
105 | typeof(ModernMessageboxButtonStatus), typeof(ModernMessageBox),
106 | new PropertyMetadata(ModernMessageboxButtonStatus.Invisibled));
107 |
108 | ///
109 | /// The status of Button3(IsEnabled and Visibility)
110 | ///
111 | public ModernMessageboxButtonStatus Button3Status
112 | {
113 | get => (ModernMessageboxButtonStatus)GetValue(Button3StatusProperty);
114 | set => SetValue(Button3StatusProperty, value);
115 | }
116 |
117 | ///
118 | /// The message to display in the messagebox
119 | ///
120 | public static readonly DependencyProperty MessageProperty = DependencyProperty.Register("Message",
121 | typeof(string), typeof(ModernMessageBox), new PropertyMetadata(string.Empty));
122 |
123 | ///
124 | /// The message to display in the messagebox
125 | ///
126 | public string Message
127 | {
128 | get => (string)GetValue(MessageProperty);
129 | set => SetValue(MessageProperty, value);
130 | }
131 |
132 | ///
133 | /// Messagebox's icon
134 | ///
135 | public static readonly DependencyProperty HeadIconProperty = DependencyProperty.Register("HeadIcon",
136 | typeof(ModernMessageboxIcons), typeof(ModernMessageBox), new PropertyMetadata(ModernMessageboxIcons.None,
137 | (sender, e) => {
138 | var current = (ModernMessageBox)sender;
139 | var newVal = (ModernMessageboxIcons)e.NewValue;
140 | if ((ModernMessageboxIcons)e.OldValue == ModernMessageboxIcons.None &&
141 | newVal != ModernMessageboxIcons.None) {
142 | current.img_HeadIcon.Visibility = Visibility.Visible;
143 | current.iconPlace.Width = new GridLength(70);
144 | }
145 |
146 | switch (newVal) {
147 | case ModernMessageboxIcons.Info:
148 | current.img_HeadPath.Data = current.Resources["icoInfo"] as Geometry;
149 | break;
150 | case ModernMessageboxIcons.Question:
151 | current.img_HeadPath.Data = current.Resources["icoHelp"] as Geometry;
152 | break;
153 | case ModernMessageboxIcons.Warning:
154 | current.img_HeadPath.Data = current.Resources["icoWarning"] as Geometry;
155 | break;
156 | case ModernMessageboxIcons.Error:
157 | current.img_HeadPath.Data = current.Resources["icoError"] as Geometry;
158 | break;
159 | case ModernMessageboxIcons.Done:
160 | current.img_HeadPath.Data = current.Resources["icoCheck"] as Geometry;
161 | break;
162 | case ModernMessageboxIcons.None:
163 | current.img_HeadIcon.Visibility = Visibility.Collapsed;
164 | current.iconPlace.Width = new GridLength(0);
165 | break;
166 | default:
167 | throw new ArgumentOutOfRangeException();
168 | }
169 | }));
170 |
171 | ///
172 | /// Messagebox's icon
173 | ///
174 | public ModernMessageboxIcons HeadIcon
175 | {
176 | get => (ModernMessageboxIcons)GetValue(HeadIconProperty);
177 | set => SetValue(HeadIconProperty, value);
178 | }
179 |
180 | ///
181 | /// control the IsEnabled attr of the close button
182 | /// The default value is True
183 | ///
184 | public static readonly DependencyProperty CloseCaptionButtonEnabledProperty =
185 | DependencyProperty.Register("CloseCaptionButtonEnabled", typeof(bool), typeof(ModernMessageBox),
186 | new PropertyMetadata(true));
187 |
188 | ///
189 | /// control the IsEnabled attr of the close button
190 | ///
191 | public bool CloseCaptionButtonEnabled
192 | {
193 | get => (bool)GetValue(CloseCaptionButtonEnabledProperty);
194 | set => SetValue(CloseCaptionButtonEnabledProperty, value);
195 | }
196 |
197 | ///
198 | /// Get or set the Visibility of the checkbox
199 | /// the default value is
200 | ///
201 | public static readonly DependencyProperty CheckboxVisibilityProperty =
202 | DependencyProperty.Register("CheckboxVisibility", typeof(Visibility), typeof(ModernMessageBox),
203 | new PropertyMetadata(Visibility.Collapsed));
204 |
205 | ///
206 | /// Get or set the Visibility of the checkbox
207 | /// the default value is
208 | ///
209 | public Visibility CheckboxVisibility
210 | {
211 | get => (Visibility)GetValue(CheckboxVisibilityProperty);
212 | set => SetValue(CheckboxVisibilityProperty, value);
213 | }
214 |
215 | ///
216 | /// Get or set the text to display on the checkbox
217 | ///
218 | public static readonly DependencyProperty CheckboxTextProperty = DependencyProperty.Register("CheckboxText",
219 | typeof(string), typeof(ModernMessageBox), new PropertyMetadata(string.Empty));
220 |
221 | ///
222 | /// Get or set the text to display on the checkbox
223 | ///
224 | public string CheckboxText
225 | {
226 | get => (string)GetValue(CheckboxTextProperty);
227 | set => SetValue(CheckboxTextProperty, value);
228 | }
229 |
230 | ///
231 | /// Get or set the IsChecked attr of the checkbox
232 | ///
233 | public static readonly DependencyProperty CheckboxCheckedProperty =
234 | DependencyProperty.Register("CheckboxChecked", typeof(bool), typeof(ModernMessageBox),
235 | new PropertyMetadata(false));
236 |
237 | ///
238 | /// Get or set the IsChecked attr of the checkbox
239 | /// The default value is false
240 | ///
241 | public bool? CheckboxChecked
242 | {
243 | get => (bool)GetValue(CheckboxCheckedProperty);
244 | set => SetValue(CheckboxCheckedProperty, value);
245 | }
246 |
247 | ///
248 | /// Get or set the text of the textbox inside the MessageBox.
249 | ///
250 | public static readonly DependencyProperty TextBoxTextProperty = DependencyProperty.Register("TextBoxText", typeof(string), typeof(ModernMessageBox), new PropertyMetadata(default(string)));
251 |
252 | ///
253 | /// Get or set the text of the textbox inside the MessageBox.
254 | ///
255 | public string TextBoxText
256 | {
257 | get => (string)GetValue(TextBoxTextProperty);
258 | set => SetValue(TextBoxTextProperty, value);
259 | }
260 |
261 | ///
262 | /// Get or set the Visibility of the textbox
263 | /// The default is
264 | ///
265 | public static readonly DependencyProperty TextBoxVisibilityProperty = DependencyProperty.Register("TextBoxVisibility", typeof(Visibility), typeof(ModernMessageBox), new PropertyMetadata(Visibility.Collapsed));
266 |
267 | ///
268 | /// Get or set the Visibility of the textbox
269 | /// The default is
270 | ///
271 | public Visibility TextBoxVisibility
272 | {
273 | get => (Visibility)GetValue(TextBoxVisibilityProperty);
274 | set => SetValue(TextBoxVisibilityProperty, value);
275 | }
276 |
277 | #endregion
278 |
279 | #region prop
280 |
281 | ///
282 | /// The key to trigger Button1
283 | ///
284 | public Key? Button1Key { get; set; }
285 |
286 | ///
287 | /// /// The key to trigger Button2
288 | ///
289 | public Key? Button2Key { get; set; }
290 |
291 | ///
292 | /// The key to trigger Button3
293 | ///
294 | public Key? Button3Key { get; set; }
295 |
296 | ///
297 | /// The key to trigger closecaptionbutton
298 | /// Default is Escape
299 | ///
300 | public Key? CloseCaptionButtonKey { get; set; } = Key.Escape;
301 |
302 | ///
303 | /// Get or set the system sound to play when the messageBox display.
304 | /// Set to null to play no sound.
305 | ///
306 | public SystemSound SoundToPlay { get; set; }
307 |
308 | ///
309 | /// Specify if the window will get a blur background in win10.
310 | /// To enable this feature, pls make sure your Background prop is not solid.
311 | /// Set this value to false if u don't need this feature.
312 | /// The default value is true.
313 | ///
314 | public bool EnableWindowBlur { get; set; }
315 | ///
316 | /// get the result of the ModernMessageBox
317 | ///
318 | public ModernMessageboxResult Result { get; private set; } = ModernMessageboxResult.Unknown;
319 |
320 | #endregion
321 |
322 | ///
323 | /// Create an object of ModernMessageBox
324 | ///
325 | public ModernMessageBox()
326 | {
327 | InitializeComponent();
328 | Background = QModernMessageBox.GlobalBackground;
329 | Foreground = QModernMessageBox.GlobalForeground;
330 | EnableWindowBlur = QModernMessageBox.GlobalEnableWindowBlur;
331 | }
332 |
333 | ///
334 | /// Create and init ModernMessageBox
335 | ///
336 | /// message to display on the messagebox
337 | /// title of the messagebox
338 | /// the icon of the messagebox
339 | /// Content of the button1
340 | /// Content of the button2
341 | /// Content of the button3
342 | /// The system sound to play in the messageBox. If you leave it null, it will set to SoundFor(headIcon). if you want to play no sound, set SoundToPlay prop to null after construct
343 | public ModernMessageBox(string message, string title,
344 | ModernMessageboxIcons headIcon = ModernMessageboxIcons.None, string button1Text = null,
345 | string button2Text = null, string button3Text = null, SystemSound soundToPlay = null)
346 | {
347 | InitializeComponent();
348 | SoundToPlay = soundToPlay ?? SoundFor(headIcon);
349 | Background = QModernMessageBox.GlobalBackground;
350 | Foreground = QModernMessageBox.GlobalForeground;
351 | EnableWindowBlur = QModernMessageBox.GlobalEnableWindowBlur;
352 | Message = message;
353 | Title = title;
354 | HeadIcon = headIcon;
355 | if (button1Text != null) {
356 | Button1Text = button1Text;
357 | }
358 |
359 | if (button2Text != null) {
360 | Button2Text = button2Text;
361 | Button2Status = ModernMessageboxButtonStatus.Normal;
362 | }
363 |
364 | // ReSharper disable once InvertIf
365 | if (button3Text != null) {
366 | Button3Text = button3Text;
367 | Button3Status = ModernMessageboxButtonStatus.Normal;
368 | }
369 | }
370 |
371 | #region Events
372 |
373 | private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
374 | {
375 | Result = ModernMessageboxResult.CloseCaptionButton;
376 | Close();
377 | }
378 |
379 | private void MetroMessageBox_OnClosing(object sender, CancelEventArgs e)
380 | {
381 | // if (_exitAnimateDone) return;
382 | // e.Cancel = true;
383 | // var sb = (Storyboard)Resources["CloseStory"];
384 | // sb.Begin();
385 | }
386 |
387 | // private void CloseStory_OnCompleted(object sender, EventArgs e)
388 | // {
389 | // _exitAnimateDone = true;
390 | // Close();
391 | // }
392 |
393 | private void UIElement_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
394 | {
395 | DragMove();
396 | }
397 |
398 | private void MetroMessageBox_OnStateChanged(object sender, EventArgs e)
399 | {
400 | if (WindowState != WindowState.Normal)
401 | WindowState = WindowState.Normal;
402 | }
403 |
404 | private void ResultButton_Click(object sender, RoutedEventArgs e)
405 | {
406 | // ReSharper disable PossibleUnintendedReferenceComparison
407 | if (sender == rbtn1)
408 | Result = ModernMessageboxResult.Button1;
409 | else if (sender == rbtn2)
410 | Result = ModernMessageboxResult.Button2;
411 | else Result = ModernMessageboxResult.Button3;
412 | // ReSharper restore PossibleUnintendedReferenceComparison
413 | Close();
414 | }
415 |
416 | private void MetroMessageBox_OnKeyUp(object sender, KeyEventArgs e)
417 | {
418 | if (!_enableKey) return;
419 | if (mainTextBox.IsKeyboardFocused) return;//inputing...
420 | if (e.Key == Button1Key && Button1Status == ModernMessageboxButtonStatus.Normal) {
421 | ResultButton_Click(rbtn1, null);
422 | }
423 | else if (e.Key == Button2Key && Button2Status == ModernMessageboxButtonStatus.Normal) {
424 | ResultButton_Click(rbtn2, null);
425 | }
426 | else if (e.Key == Button3Key && Button3Status == ModernMessageboxButtonStatus.Normal) {
427 | ResultButton_Click(rbtn3, null);
428 | }
429 | else if (e.Key == CloseCaptionButtonKey && CloseCaptionButtonEnabled) {
430 | ButtonBase_OnClick(null, null);
431 | }
432 | }
433 |
434 | #endregion
435 |
436 | private async void ModernMessageBox_OnLoaded(object sender, RoutedEventArgs e)
437 | {
438 | if ( !EnableWindowBlur || !WindowBlurBackgroundHelper.BlurWindow(this)) {
439 | if (Background is SolidColorBrush scb) {
440 |
441 | var col = scb.Color;
442 | col.A = byte.MaxValue;
443 | Background = new SolidColorBrush(col);
444 | }
445 | Background.Opacity = 1;
446 | }
447 |
448 | SoundToPlay?.Play();
449 |
450 | //Issue fix
451 | //When user use Enter button to open a msgbox.
452 | //The msgbox will close because the key event.
453 | await Task.Delay(100);
454 | _enableKey = true;
455 | }
456 |
457 |
458 | ///
459 | /// get the sound of the icon in Windows MessageBox
460 | ///
461 | ///
462 | ///
463 | public static SystemSound SoundFor(ModernMessageboxIcons ico)
464 | {
465 | switch (ico) {
466 | case ModernMessageboxIcons.Info:
467 | return SystemSounds.Asterisk;
468 | case ModernMessageboxIcons.Question:
469 | return SystemSounds.Question;
470 | case ModernMessageboxIcons.Warning:
471 | return SystemSounds.Exclamation;
472 | case ModernMessageboxIcons.Error:
473 | return SystemSounds.Hand;
474 | case ModernMessageboxIcons.Done:
475 | return SystemSounds.Asterisk;
476 | case ModernMessageboxIcons.None:
477 | return null;
478 | default:
479 | throw new ArgumentOutOfRangeException(nameof(ico), ico, null);
480 | }
481 | }
482 | }
483 | }
484 |
--------------------------------------------------------------------------------
/ModernMessageBoxLib/ModernMessageBoxLib.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {BA88D9E1-3978-4092-AE72-9A82BAF65F15}
8 | library
9 | ModernMessageBoxLib
10 | ModernMessageBoxLib
11 | v4.5
12 | 512
13 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
14 | 4
15 |
16 |
17 |
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 2
25 |
26 |
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 | bin\Release\ModernMessageBoxLib.xml
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | 4.0
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | ModernMessageBox.xaml
56 |
57 |
58 |
59 |
60 |
61 |
62 | ProcessRing.xaml
63 |
64 |
65 | Code
66 |
67 |
68 | True
69 | True
70 | Resources.resx
71 |
72 |
73 | True
74 | Settings.settings
75 | True
76 |
77 |
78 |
79 | IndeterminateProgressWindow.xaml
80 |
81 |
82 | ResXFileCodeGenerator
83 | Resources.Designer.cs
84 |
85 |
86 |
87 | SettingsSingleFileGenerator
88 | Settings.Designer.cs
89 |
90 |
91 |
92 |
93 | Designer
94 | MSBuild:Compile
95 |
96 |
97 | MSBuild:Compile
98 | Designer
99 |
100 |
101 | Designer
102 | MSBuild:Compile
103 |
104 |
105 | MSBuild:Compile
106 | Designer
107 |
108 |
109 |
110 |
--------------------------------------------------------------------------------
/ModernMessageBoxLib/ModernMessageBoxLib.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $id$
5 | $version$
6 | Modern MessageBox For WPF by SakuraTrak Studio
7 | Saber0905
8 | Saber0905
9 | https://github.com/hv0905/ModernMessageBoxLibForWPF
10 |
11 | false
12 | Create and show a Modern MessageBox with a single code.
13 | Publish ModernMessageBoxLib.
14 | Copyright 2018
15 | C# .net WPF Modern VB.Net MessageBox Message Box MsgBox
16 |
17 |
18 |
--------------------------------------------------------------------------------
/ModernMessageBoxLib/ModernMessageboxButtonStatus.cs:
--------------------------------------------------------------------------------
1 | namespace ModernMessageBoxLib
2 | {
3 | ///
4 | /// Define the status of the button on the ModernMessageBox
5 | ///
6 | public enum ModernMessageboxButtonStatus
7 | {
8 | ///
9 | /// Display and enabled the button
10 | ///
11 | Normal,
12 | ///
13 | /// Display and disabled the button
14 | ///
15 | Disabled,
16 | ///
17 | /// Hide the button
18 | ///
19 | Invisibled
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/ModernMessageBoxLib/ModernMessageboxButtonStatusConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using System.Windows;
4 | using System.Windows.Data;
5 | using System.Windows.Media;
6 |
7 | namespace ModernMessageBoxLib
8 | {
9 | internal class ModernMessageboxButtonStatusConverter : IValueConverter
10 | {
11 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
12 | {
13 | // ReSharper disable once PossibleNullReferenceException
14 | var tmp = (ModernMessageboxButtonStatus)value;
15 | if (targetType == typeof(Visibility)) {
16 | return tmp == ModernMessageboxButtonStatus.Invisibled ? Visibility.Collapsed : Visibility.Visible;
17 | }
18 |
19 | if (targetType == typeof(bool)) {
20 | return tmp != ModernMessageboxButtonStatus.Disabled;
21 | }
22 |
23 | throw new ArgumentException(nameof(targetType));
24 | }
25 |
26 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
27 | throw new NotImplementedException();
28 | }
29 |
30 |
31 | internal class ColorOpticityConverter : IValueConverter
32 | {
33 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
34 | {
35 | Color col;
36 | if (value is SolidColorBrush brush) {
37 | col = brush.Color;
38 | }else if (value is Color color) {
39 | col = color;
40 | }else throw new ArgumentException(nameof(value));
41 |
42 | col.A = byte.MaxValue;
43 |
44 | if (targetType.IsSubclassOf(typeof(Brush)) || targetType == typeof(Brush)) {
45 | return new SolidColorBrush(col);
46 | }else if (targetType == typeof(Color)) {
47 | return col;
48 | }else throw new ArgumentException(nameof(targetType));
49 | }
50 |
51 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => Convert(value, targetType, parameter, culture);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/ModernMessageBoxLib/ModernMessageboxIcons.cs:
--------------------------------------------------------------------------------
1 | namespace ModernMessageBoxLib
2 | {
3 | ///
4 | /// Defind the icon to display on the ModernMessageBox
5 | ///
6 | public enum ModernMessageboxIcons
7 | {
8 | ///
9 | /// (i)
10 | ///
11 | Info,
12 | ///
13 | /// (?)
14 | ///
15 | Question,
16 | ///
17 | /// ⚠
18 | ///
19 | Warning,
20 | ///
21 | /// (X)
22 | ///
23 | Error,
24 | ///
25 | /// (√)
26 | ///
27 | Done,
28 | ///
29 | /// No any icons
30 | ///
31 | None,
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/ModernMessageBoxLib/ModernMessageboxResult.cs:
--------------------------------------------------------------------------------
1 | namespace ModernMessageBoxLib
2 | {
3 | ///
4 | /// Define the button result of the ModernMessageBox
5 | ///
6 | public enum ModernMessageboxResult
7 | {
8 | ///
9 | /// The first button in the window from left to right (yes,ok,...)
10 | ///
11 | Button1,
12 | ///
13 | /// The second button in the window from left to right (no,cancel,...)
14 | ///
15 | Button2,
16 | ///
17 | /// The third button in the window from left to right (cancel,...)
18 | ///
19 | Button3,
20 | ///
21 | /// the "Close" button on the right top side
22 | ///
23 | CloseCaptionButton,
24 | ///
25 | /// The window haven't closed or Unknown(Maybe the user closed the window by clicking Alt+F4)
26 | ///
27 | Unknown,
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/ModernMessageBoxLib/ProcessRing.xaml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
93 |
94 |
--------------------------------------------------------------------------------
/ModernMessageBoxLib/ProcessRing.xaml.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using System.Windows.Media.Animation;
3 |
4 | namespace ModernMessageBoxLib
5 | {
6 |
7 | internal partial class ProcessRing
8 | {
9 | private Storyboard _trans;
10 |
11 | public ProcessRing()
12 | {
13 | InitializeComponent();
14 | _trans = Resources["Trans"] as Storyboard;
15 | Loaded += (sender, e) => Active();
16 | }
17 |
18 | private async void Active()
19 | {
20 | //e1.BeginStoryboard(_trans);
21 | //await Task.Delay(100);
22 | e2.BeginStoryboard(_trans);
23 | await Task.Delay(170);
24 | e3.BeginStoryboard(_trans);
25 | await Task.Delay(170);
26 | e4.BeginStoryboard(_trans);
27 | await Task.Delay(170);
28 | e5.BeginStoryboard(_trans);
29 | await Task.Delay(170);
30 | e6.BeginStoryboard(_trans);
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/ModernMessageBoxLib/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.InteropServices;
4 | using System.Windows;
5 |
6 | // 有关程序集的一般信息由以下
7 | // 控制。更改这些特性值可修改
8 | // 与程序集关联的信息。
9 | [assembly: AssemblyTitle("ModernMessageBoxLib")]
10 | [assembly: AssemblyDescription("A Library to Display a modern-style messageBox in WPF")]
11 | [assembly: AssemblyConfiguration("")]
12 | [assembly: AssemblyCompany("Sakuratrak Studio")]
13 | [assembly: AssemblyProduct("ModernMessageBoxLib")]
14 | [assembly: AssemblyCopyright("Copyright © 2018")]
15 | [assembly: AssemblyTrademark("SakuraTrak Studio")]
16 | [assembly: AssemblyCulture("")]
17 |
18 | // 将 ComVisible 设置为 false 会使此程序集中的类型
19 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
20 | //请将此类型的 ComVisible 特性设置为 true。
21 | [assembly: ComVisible(false)]
22 |
23 | //若要开始生成可本地化的应用程序,请设置
24 | //.csproj 文件中的 CultureYouAreCodingWith
25 | //例如,如果您在源文件中使用的是美国英语,
26 | //使用的是美国英语,请将 设置为 en-US。 然后取消
27 | //对以下 NeutralResourceLanguage 特性的注释。 更新
28 | //以下行中的“en-US”以匹配项目文件中的 UICulture 设置。
29 |
30 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
31 |
32 |
33 | [assembly:ThemeInfo(
34 | ResourceDictionaryLocation.None, //主题特定资源词典所处位置
35 | //(未在页面中找到资源时使用,
36 | //或应用程序资源字典中找到时使用)
37 | ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
38 | //(未在页面中找到资源时使用,
39 | //、应用程序或任何主题专用资源字典中找到时使用)
40 | )]
41 |
42 |
43 | // 程序集的版本信息由下列四个值组成:
44 | //
45 | // 主版本
46 | // 次版本
47 | // 生成号
48 | // 修订号
49 | //
50 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
51 | // 方法是按如下所示使用“*”: :
52 | // [assembly: AssemblyVersion("1.0.*")]
53 | [assembly: AssemblyVersion("1.3.1.0")]
54 | [assembly: AssemblyFileVersion("1.3.1.0")]
55 | [assembly: NeutralResourcesLanguage("")]
56 |
57 |
--------------------------------------------------------------------------------
/ModernMessageBoxLib/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.42000
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ModernMessageBoxLib.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// 一个强类型的资源类,用于查找本地化的字符串等。
17 | ///
18 | // 此类是由 StronglyTypedResourceBuilder
19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
21 | // (以 /str 作为命令选项),或重新生成 VS 项目。
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// 返回此类使用的缓存的 ResourceManager 实例。
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ModernMessageBoxLib.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// 重写当前线程的 CurrentUICulture 属性
51 | /// 重写当前线程的 CurrentUICulture 属性。
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/ModernMessageBoxLib/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/ModernMessageBoxLib/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.42000
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ModernMessageBoxLib.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.8.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/ModernMessageBoxLib/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/ModernMessageBoxLib/QModernMessageBox.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows;
3 | using System.Windows.Input;
4 | using System.Windows.Media;
5 |
6 | namespace ModernMessageBoxLib
7 | {
8 | ///
9 | /// Common usage of ModernMessageBox,
10 | /// Just like using in WPF or using QMessageBox in QT
11 | ///
12 | public static class QModernMessageBox
13 | {
14 | ///
15 | /// Get or set the default owner of the MessageBoxWindow
16 | ///
17 | public static Window GlobalParentWindow { get; set; }
18 |
19 | ///
20 | /// Get or set the text of the buttons
21 | /// The default value is in English. If you want other language, you should specify them manully
22 | ///
23 | public static QMetroMessageLang MainLang { get; set; } = new QMetroMessageLang();
24 |
25 | ///
26 | /// Specify the default Background for ModernMessageBox
27 | /// You can specify a transparent or half-transparent value in this field.
28 | /// If the operate system is Win10, The window will get a Blur background.
29 | /// The default value is Black,0.6 Opacity
30 | ///
31 | public static Brush GlobalBackground { get; set; } = new SolidColorBrush(Colors.Black) {Opacity = 0.6};
32 | ///
33 | /// Specify the default Foreground for ModernMessageBox
34 | /// The default value is White
35 | ///
36 | public static Brush GlobalForeground { get; set; } = Brushes.White;
37 |
38 | ///
39 | /// Specify if the window will get a blur background in win10.
40 | /// To enable this feature, pls make sure your Background prop is not solid.
41 | /// Set this value to false if u don't need this feature.
42 | /// The default value is true.
43 | ///
44 | public static bool GlobalEnableWindowBlur { get; set; } = true;
45 |
46 | ///
47 | /// Create and show a Modern Messagebox
48 | ///
49 | /// the owner of the messagebox window
50 | /// Message
51 | /// Title
52 | ///
53 | /// The bottons to show
54 | ///
55 | ///
56 | /// The icon to show
57 | ///
58 | /// play the system sound when the messageBox show
59 | public static ModernMessageboxResult Show(Window parentWindow, string msg, string title,
60 | QModernMessageBoxButtons btns,
61 | ModernMessageboxIcons icon = ModernMessageboxIcons.None,
62 | bool playSound = true)
63 | {
64 | var msgBox = new ModernMessageBox(msg, title, icon) {
65 | Background = GlobalBackground,
66 | Foreground = GlobalForeground,
67 | Owner = parentWindow,
68 | };
69 | switch (btns) {
70 | case QModernMessageBoxButtons.Ok:
71 | msgBox.Button1Text = MainLang.Ok;
72 | msgBox.Button1Key = Key.Enter;
73 | break;
74 | case QModernMessageBoxButtons.OkCancel:
75 | msgBox.Button1Text = MainLang.Ok;
76 | msgBox.Button1Key = Key.Enter;
77 | msgBox.Button2Status = ModernMessageboxButtonStatus.Normal;
78 | msgBox.Button2Text = MainLang.Cancel;
79 | msgBox.Button2Key = Key.Escape;
80 | break;
81 | case QModernMessageBoxButtons.YesNo:
82 | msgBox.Button1Text = MainLang.Yes;
83 | msgBox.Button1Key = Key.Y;
84 | msgBox.Button2Status = ModernMessageboxButtonStatus.Normal;
85 | msgBox.Button2Text = MainLang.No;
86 | msgBox.Button2Key = Key.N;
87 | msgBox.CloseCaptionButtonEnabled = false;
88 | break;
89 | case QModernMessageBoxButtons.YesNoCancel:
90 | msgBox.Button1Text = MainLang.Yes;
91 | msgBox.Button1Key = Key.Y;
92 | msgBox.Button2Status = ModernMessageboxButtonStatus.Normal;
93 | msgBox.Button2Text = MainLang.No;
94 | msgBox.Button2Key = Key.N;
95 | msgBox.Button3Status = ModernMessageboxButtonStatus.Normal;
96 | msgBox.Button3Text = MainLang.Cancel;
97 | msgBox.Button3Key = Key.Escape;
98 | break;
99 | case QModernMessageBoxButtons.AbortRetryIgnore:
100 | msgBox.Button1Text = MainLang.Abort;
101 | msgBox.Button1Key = Key.A;
102 | msgBox.Button2Status = ModernMessageboxButtonStatus.Normal;
103 | msgBox.Button2Text = MainLang.Retry;
104 | msgBox.Button2Key = Key.R;
105 | msgBox.Button3Status = ModernMessageboxButtonStatus.Normal;
106 | msgBox.Button3Text = MainLang.Ignore;
107 | msgBox.Button3Key = Key.I;
108 | msgBox.CloseCaptionButtonEnabled = false;
109 | break;
110 | default:
111 | throw new ArgumentOutOfRangeException(nameof(btns), btns, null);
112 | }
113 |
114 | msgBox.ShowDialog();
115 | return msgBox.Result;
116 | }
117 |
118 | ///
119 | /// Create and show a Modern Messagebox
120 | ///
121 | /// Message
122 | /// Title
123 | ///
124 | /// The bottons to show
125 | ///
126 | ///
127 | /// The icon to show
128 | ///
129 | /// play the system sound when the messageBox show
130 | public static ModernMessageboxResult Show(string msg, string title, QModernMessageBoxButtons btns,
131 | ModernMessageboxIcons icon = ModernMessageboxIcons.None,
132 | bool playSound = true) => Show(GlobalParentWindow, msg, title, btns, icon,
133 | playSound);
134 |
135 | ///
136 | /// Create and show a metro messagebox with a warning sign and a "OK" button
137 | ///
138 | /// Message
139 | /// Title
140 | public static void Warning(string msg, string title) =>
141 | Show(msg, title, QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Warning);
142 |
143 | ///
144 | /// Create and show a metro messagebox with a warning sign and a "OK" button
145 | ///
146 | /// the owner of the messagebox window
147 | /// Message
148 | /// Title
149 | public static void Warning(Window parentWindow, string msg, string title) =>
150 | Show(parentWindow, msg, title, QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Warning);
151 |
152 | ///
153 | /// Create and show a metro messagebox with an infomation sign and a "OK" button
154 | ///
155 | /// Message
156 | /// Title
157 | public static void Info(string msg, string title) =>
158 | Show(msg, title, QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Info);
159 |
160 | ///
161 | /// Create and show a metro messagebox with an infomation sign and a "OK" button
162 | ///
163 | /// the owner of the messagebox window
164 | /// Message
165 | /// Title
166 | public static void Info(Window parentWindow, string msg, string title) =>
167 | Show(parentWindow, msg, title, QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Info);
168 |
169 | ///
170 | /// Create and show a metro messagebox with an error sign and a "OK" button
171 | ///
172 | /// Message
173 | /// Title
174 | public static void Error(string msg, string title) =>
175 | Show(msg, title, QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Error);
176 |
177 | ///
178 | /// Create and show a metro messagebox with an error sign and a "OK" button
179 | ///
180 | /// the owner of the messagebox window
181 | /// Message
182 | /// Title
183 | public static void Error(Window parentWindow,string msg, string title) =>
184 | Show(parentWindow,msg, title, QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Error);
185 |
186 | ///
187 | /// Create and show a metro messagebox with a question sign and a "OK" button
188 | ///
189 | /// Message
190 | /// Title
191 | public static void Question(string msg, string title) =>
192 | Show(msg, title, QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Question);
193 |
194 | ///
195 | /// Create and show a metro messagebox with a question sign and a "OK" button
196 | ///
197 | /// the owner of the messagebox window
198 | /// Message
199 | /// Title
200 | public static void Question(Window parentWindow, string msg, string title) =>
201 | Show(parentWindow, msg, title, QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Question);
202 |
203 | ///
204 | /// Create and show a metro messagebox with a "OK" button
205 | ///
206 | /// Message
207 | /// Title
208 | public static void None(string msg, string title) => Show(msg, title, QModernMessageBoxButtons.Ok);
209 |
210 | ///
211 | /// Create and show a metro messagebox with a "OK" button
212 | ///
213 | /// the owner of the messagebox window
214 | /// Message
215 | /// Title
216 | public static void None(Window parentWindow, string msg, string title) =>
217 | Show(parentWindow, msg, title, QModernMessageBoxButtons.Ok);
218 |
219 | ///
220 | /// Create and show a metro messagebox with a done sign and a "OK" button
221 | ///
222 | /// Message
223 | /// Title
224 | public static void Done(string msg, string title) =>
225 | Show(msg, title, QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Done);
226 |
227 | ///
228 | /// Create and show a metro messagebox with a done sign and a "OK" button
229 | ///
230 | /// the owner of the messagebox window
231 | /// Message
232 | /// Title
233 | public static void Done(Window parentWindow, string msg, string title) =>
234 | Show(parentWindow, msg, title, QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Done);
235 |
236 | ///
237 | /// Define the buttons on the QModernMessageBox
238 | ///
239 | public enum QModernMessageBoxButtons
240 | {
241 | ///
242 | /// Button1:OK
243 | ///
244 | Ok,
245 | ///
246 | /// Button1:OK
247 | /// Button2:Cancel
248 | ///
249 | OkCancel,
250 | ///
251 | /// Button1:Yes
252 | /// Button2:No
253 | ///
254 | YesNo,
255 | ///
256 | /// Button1:Yes
257 | /// Button2:No
258 | /// Button3:Cancel
259 | ///
260 | YesNoCancel,
261 | ///
262 | /// Button1:Abort
263 | /// Button2:Retry
264 | /// Button3:Ignore
265 | ///
266 | AbortRetryIgnore,
267 | }
268 | }
269 |
270 | ///
271 | /// Provide language setting for QMessageBox
272 | /// the default language is in English
273 | ///
274 | public class QMetroMessageLang
275 | {
276 | ///
277 | /// get or set the display of the OK button
278 | ///
279 | public string Ok { get; set; } = "OK";
280 | ///
281 | /// get or set the display of the Cancel button
282 | ///
283 | public string Cancel { get; set; } = "Cancel";
284 | ///
285 | /// get or set the display of the Yes button
286 | ///
287 | public string Yes { get; set; } = "Yes";
288 | ///
289 | /// get or set the display of the No button
290 | ///
291 | public string No { get; set; } = "No";
292 | ///
293 | /// get or set the display of the Ignore button
294 | ///
295 | public string Ignore { get; set; } = "Ignore";
296 | ///
297 | /// get or set the display of the Retry button
298 | ///
299 | public string Retry { get; set; } = "Retry";
300 | ///
301 | /// get or set the display of the Abort button
302 | ///
303 | public string Abort { get; set; } = "Abort";
304 | }
305 | }
306 |
--------------------------------------------------------------------------------
/ModernMessageBoxLib/Themes/ModernButtons.xaml:
--------------------------------------------------------------------------------
1 |
4 |
5 | M12,2L1,21H23M12,6L19.53,19H4.47M11,10V14H13V10M11,16V18H13V16
6 | M12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22A10,10 0 0,1 2,12A10,10 0 0,1 12,2M12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20A8,8 0 0,0 20,12A8,8 0 0,0 12,4M11,16.5L6.5,12L7.91,10.59L11,13.67L16.59,8.09L18,9.5L11,16.5Z
7 | M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2C6.47,2 2,6.47 2,12C2,17.53 6.47,22 12,22C17.53,22 22,17.53 22,12C22,6.47 17.53,2 12,2M14.59,8L12,10.59L9.41,8L8,9.41L10.59,12L8,14.59L9.41,16L12,13.41L14.59,16L16,14.59L13.41,12L16,9.41L14.59,8Z
8 | M11,18H13V16H11V18M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,6A4,4 0 0,0 8,10H10A2,2 0 0,1 12,8A2,2 0 0,1 14,10C14,12 11,11.75 11,15H13C13,12.75 16,12.5 16,10A4,4 0 0,0 12,6Z
9 | M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z
10 | M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z
11 |
96 |
97 |
111 |
183 |
184 |
204 |
205 |
293 |
302 |
303 |
--------------------------------------------------------------------------------
/ModernMessageBoxLib/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # ModernMessageBoxLib
2 | ModernMessageBoxLib is a WPF library in .Net 4.5
3 | By using ModernMessageBoxLib, you can create a ModernMessageBox with a single code.
4 |
5 | [](https://www.nuget.org/packages/ModernMessageBoxLib/)
6 | [](https://www.nuget.org/packages/ModernMessageBoxLib/)
7 | [](https://dev.azure.com/sakuratrak/ModernMessageBoxLibForWPF)
8 | [](https://www.nuget.org/packages/ModernMessageBoxLib/)
9 |
10 | ## Todo list
11 |
12 | - [x] Basic MessageBox
13 | - [x] Input Window
14 | - [x] Waiting window
15 | - [ ] Color Picker
16 | - [ ] avater crop window
17 |
18 | ## Screenshots
19 | ### ModernMessageBox
20 |
21 | 
22 |
23 | 
24 |
25 | 
26 |
27 | ### IndeterminateProgressWindow
28 |
29 | 
30 |
31 | ## Import
32 |
33 | We are strongly recommend you to use Nuget to import the package.
34 | Run this command in Package Manage Console:
35 | ```
36 | PM> Install-Package ModernMessageBoxLib
37 | ```
38 | _(See more in [Nuget](https://www.nuget.org/packages/ModernMessageBoxLib/))_
39 |
40 | Or you can download it on Release Page.
41 |
42 | ## Get Started
43 |
44 | ### ModernMessageBox
45 |
46 | Before start using, you should specify Language and Background and Foreground.
47 | See
48 | * _QModernMessageBox.MainLang_
49 |
50 | * _QModernMessageBox.GlobalBackground_
51 |
52 | * _QModernMessageBox.GlobalForeground_
53 |
54 | Example:
55 | ```C#
56 | QModernMessageBox.MainLang = new QMetroMessageLang() {
57 | Ok = "确定",
58 | Cancel = "取消",
59 | Abort = "中止(A)",
60 | Ignore = "忽略(I)",
61 | No = "否(N)",
62 | Yes = "是(Y)",
63 | Retry = "重试(R)"
64 | };
65 | QModernMessageBox.GlobalBackground = new SolidColorBrush(Colors.White){Opacity = 0.6};
66 | QModernMessageBox.GlobalForeground = Brushes.Black;
67 | ```
68 | In this example, The button text of the ModernMessageBox set to Chinese and Background set to white with 60% opacity and Foreground set to Black.
69 |
70 | Those setting will use as default in ModernMessageBox.
71 |
72 | > The default Background in MessageBox is Black, 60% Opacity and the Foreground is White
73 | >
74 | > The default lang is in English
75 |
76 | > In background setting, you can use a color with not fully solid.
77 | > In this way, the window will have a Gaussian Blur background in Win10 1803+
78 | > In win7/8/8.1 or early version of win10, it will still use the solid color as background.
79 | > If you don't want a gaussian blur, just set the color solid.
80 |
81 |
82 | In common cases, you can create a MetroMessageBox with the following code
83 | ```C#
84 | QModernMessageBox.Show("The quick brown fox jumps over the lazy dog.", "hello world",QModernMessageBox.QModernMessageBoxButtons.YesNoCancel,ModernMessageboxIcons.Warning);
85 | ```
86 |
87 | Or using the QT way:
88 | ```C#
89 | QModernMessageBox.Warning("The quick brown fox jumps over the lazy dog.", "hello world");
90 | ```
91 |
92 | Customize:
93 | ```C#
94 | var msg = new ModernMessageBox("The quick brown fox jumps over the lazy dog.\n", "hello world", ModernMessageboxIcons.Info, "CSharp", "Java",
95 | "Python") {
96 | Button1Key = Key.D1,
97 | Button2Key = Key.D2,
98 | Button3Key = Key.D3,
99 | CheckboxText = "Don't show this again",
100 | CheckboxVisibility = Visibility.Visible,
101 | TextBoxText = "some staff",
102 | TextBoxVisibility = Visibility.Visible,
103 | };
104 |
105 | msg.ShowDialog();
106 | ```
107 |
108 | ### IndeterminateProgressWindow
109 | Before start using, you should specify Background and Foreground.
110 | See:
111 |
112 | * _IndeterminateProgressWindow.GlobalBackground_
113 |
114 | * _IndeterminateProgressWindow.GlobalForeground_
115 |
116 | Usage:
117 | ```C#
118 | var win = new IndeterminateProgressWindow("Please wait while we are installing the virus into your computer. . .");
119 | win.Show();
120 | //Do Some Staff
121 | await Task.Delay(5000);
122 | //Change the message the 2nd time
123 | win.Message = "Done!!!";
124 | win.Close();
125 | ```
126 |
127 |
128 | See more in the XML document comment.
129 |
130 | # About
131 |
132 | Using this library means you agree the MIT Licence.
133 | Build with ❤ By Saber0905 in SakuraTrak Studio
134 |
--------------------------------------------------------------------------------
/web/sc1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hv0905/ModernMessageBoxLibForWPF/6fb7f4dfe7d3354e6012b07238404116585045a5/web/sc1.png
--------------------------------------------------------------------------------
/web/sc2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hv0905/ModernMessageBoxLibForWPF/6fb7f4dfe7d3354e6012b07238404116585045a5/web/sc2.png
--------------------------------------------------------------------------------
/web/sc3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hv0905/ModernMessageBoxLibForWPF/6fb7f4dfe7d3354e6012b07238404116585045a5/web/sc3.png
--------------------------------------------------------------------------------
/web/sc4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hv0905/ModernMessageBoxLibForWPF/6fb7f4dfe7d3354e6012b07238404116585045a5/web/sc4.png
--------------------------------------------------------------------------------