├── .gitattributes
├── .gitignore
├── README.md
├── build
├── WPFCustomMessageBox.nuspec
└── build-release.cmd
└── source
├── CustomMessageBoxDemo
├── App.xaml
├── App.xaml.cs
├── CustomMessageBox Demo.csproj
├── MainWindow.xaml
├── MainWindow.xaml.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
└── app.config
├── WPFCustomMessageBox.sln
└── WPFCustomMessageBox
├── App.xaml
├── App.xaml.cs
├── CustomMessageBox.cs
├── CustomMessageBoxWindow.xaml
├── CustomMessageBoxWindow.xaml.cs
├── MessageBoxData.cs
├── Properties
├── AssemblyInfo.cs
├── Resources.Designer.cs
├── Resources.resx
├── Settings.Designer.cs
└── Settings.settings
├── Util.cs
├── WPFCustomMessageBox.csproj
└── blankicon.ico
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
2 | [Bb]in/
3 | [Oo]bj/
4 |
5 | # mstest test results
6 | TestResults
7 |
8 | ## Ignore Visual Studio temporary files, build results, and
9 | ## files generated by popular Visual Studio add-ons.
10 |
11 | # User-specific files
12 | *.suo
13 | *.user
14 | *.sln.docstates
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Rr]elease/
19 | x64/
20 | *_i.c
21 | *_p.c
22 | *.ilk
23 | *.meta
24 | *.obj
25 | *.pch
26 | *.pdb
27 | *.pgc
28 | *.pgd
29 | *.rsp
30 | *.sbr
31 | *.tlb
32 | *.tli
33 | *.tlh
34 | *.tmp
35 | *.log
36 | *.vspscc
37 | *.vssscc
38 | .builds
39 |
40 | # Visual C++ cache files
41 | ipch/
42 | *.aps
43 | *.ncb
44 | *.opensdf
45 | *.sdf
46 |
47 | # Visual Studio profiler
48 | *.psess
49 | *.vsp
50 | *.vspx
51 |
52 | # Guidance Automation Toolkit
53 | *.gpState
54 |
55 | # ReSharper is a .NET coding add-in
56 | _ReSharper*
57 |
58 | # NCrunch
59 | *.ncrunch*
60 | .*crunch*.local.xml
61 |
62 | # Installshield output folder
63 | [Ee]xpress
64 |
65 | # DocProject is a documentation generator add-in
66 | DocProject/buildhelp/
67 | DocProject/Help/*.HxT
68 | DocProject/Help/*.HxC
69 | DocProject/Help/*.hhc
70 | DocProject/Help/*.hhk
71 | DocProject/Help/*.hhp
72 | DocProject/Help/Html2
73 | DocProject/Help/html
74 |
75 | # Click-Once directory
76 | publish
77 |
78 | # Publish Web Output
79 | *.Publish.xml
80 |
81 | # NuGet Packages Directory
82 | packages
83 |
84 | # Windows Azure Build Output
85 | csx
86 | *.build.csdef
87 |
88 | # Windows Store app package directory
89 | AppPackages/
90 |
91 | # Others
92 | [Bb]in
93 | [Oo]bj
94 | sql
95 | TestResults
96 | [Tt]est[Rr]esult*
97 | *.Cache
98 | ClientBin
99 | [Ss]tyle[Cc]op.*
100 | ~$*
101 | *.dbmdl
102 | Generated_Code #added for RIA/Silverlight projects
103 |
104 | # Backup & report files from converting an old project file to a newer
105 | # Visual Studio version. Backup files are not needed, because we have git ;-)
106 | _UpgradeReport_Files/
107 | Backup*/
108 | UpgradeLog*.XML
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | WPFCustomMessageBox
2 | =====================
3 |
4 | *WPFCustomMessageBox* is a WPF clone of the native Windows/.NET MessageBox with extra features like custom button text.
5 |
6 | 
7 |
8 | I created this library because I wanted to use verbs for my MessageBox buttons to [help users better understand the functionality of the buttons](http://ux.stackexchange.com/a/9960/12349) - which isn't possible in the standard Windows MessageBox. With this library, you can offer your users button descriptions like `Save/Don't Save` or `Shutdown Reactor/Eject Spent Fuel Rods` rather than the standard `OK/Cancel` or `Yes/No` (although you can still use those too, if you like).
9 |
10 | The WPFCustomMessageBox message boxes return [standard .NET MessageBoxResults](http://msdn.microsoft.com/en-us/library/system.windows.messageboxresult%28v=vs.100%29.aspx).
11 |
12 | ## Downloading and Installing ##
13 |
14 | [WPFCustomMessageBox is available via NuGet](https://www.nuget.org/packages/WPFCustomMessageBox/).
15 |
16 | ## Usage ##
17 |
18 | This documentation is still in progress, so in the meantime you can explore the `CustomMessageBoxDemo` project which should have a variety of demos.
19 |
20 | WPFCustomMessageBox uses static methods just like the standard .NET MessageBox, so you can plug-and-play the new library without modifying any code. When you want to add custom text, just use the special methods outlined below.
21 |
22 | **Standard .NET Message Box**
23 |
24 |
25 | ```csharp
26 | MessageBox.Show("Hello World!", "This is the title of the MessageBox", MessageBoxButton.OKCancel);
27 | ```
28 |
29 | **WPFCustomMessageBox Equivalent**
30 |
31 |
32 | ```csharp
33 | using WPFCustomMessageBox;
34 |
35 | CustomMessageBox.Show("Hello World!", "This is the title of the MessageBox", MessageBoxButton.OKCancel);
36 | ```
37 |
38 | **Adding custom button text to WPFCustomMessageBox**
39 |
40 | ```csharp
41 | using WPFCustomMessageBox;
42 |
43 | CustomMessageBox.ShowOKCancel(
44 | "Are you sure you want to eject the nuclear fuel rods?",
45 | "Confirm Fuel Ejection",
46 | "Eject Fuel Rods",
47 | "Don't do it!");
48 | ```
49 |
50 | **Custom Button Methods**
51 |
52 | The WPFCustomMessageBox library provides customizable equivalents of all .NET MessageBox button types:
53 |
54 | * `CustomMessageBox.Show()` - Standard MessageBox
55 | * `CustomMessageBox.ShowOK()` - MessageBox with single customizable "OK" button. Returns `MessageBoxResult.OK`.
56 | * `CustomMessageBox.ShowOKCancel()` - MessageBox with customizable "OK" and "Cancel" buttons. Returns either `MessageBoxResult.OK` or `MessageBoxResult.Cancel`.
57 | * `CustomMessageBox.ShowYesNo()` - MessageBox with customizable "Yes" and "No" buttons. Returns either `MessageBoxResult.Yes` or `MessageBoxResult.No`.
58 | * `CustomMessageBox.ShowYesNoCancel()` - MessageBox with customizable "Yes", "No", and "Cancel" buttons. Returns either `MessageBoxResult.Yes`, `MessageBoxResult.No`, or `MessageBoxResult.Cancel`.
59 |
60 | ## Todo ##
61 |
62 | * i18n support (especially for languages that read right-to-left)
63 |
64 | ## License ##
65 |
66 | **The MIT License**
67 |
68 | Copyright (c) 2013 Evan Wondrasek / Apricity Software LLC
69 |
70 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
71 |
72 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
73 |
74 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
75 |
--------------------------------------------------------------------------------
/build/WPFCustomMessageBox.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | WPFCustomMessageBox
5 | 1.0.7
6 | WPF Custom MessageBox
7 | Evan Wondrasek / Apricity Software LLC
8 | https://github.com/evanwon/WPFCustomMessageBox/blob/master/README.md
9 | false
10 | A WPF clone of the native Windows/.NET MessageBox with extra features like custom button text.
11 |
12 | Added XML documentation file for IntelliSense
13 | Evan Wondrasek / Apricity Software LLC
14 | en-US
15 | wpf messagebox
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/build/build-release.cmd:
--------------------------------------------------------------------------------
1 | :: http://msdn.microsoft.com/en-us/library/vstudio/ms164311.aspx
2 |
3 | @ECHO OFF
4 |
5 | SET msbuild="%ProgramFiles(x86)%\MSBuild\12.0\Bin\msbuild.exe"
6 |
7 | :: delete existing build
8 | del "..\source\WPFCustomMessageBox\bin\Release\" /q /s
9 |
10 | IF '%1'=='' (SET configuration=Release) ELSE (SET configuration=%1)
11 | IF '%2'=='' (SET platform="Any CPU") ELSE (SET platform=%2)
12 |
13 | %msbuild% "../source/WPFCustomMessageBox.sln" /t:Rebuild /nologo /property:Platform=%platform% /property:Configuration=%configuration% /property:DebugSymbols=false /property:DebugType=None /property:AllowedReferenceRelatedFileExtensions=- /verbosity:minimal /flp:verbosity=normal;logfile=build-release.log
14 |
15 | IF NOT ERRORLEVEL 0 EXIT /B %ERRORLEVEL%
--------------------------------------------------------------------------------
/source/CustomMessageBoxDemo/App.xaml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/source/CustomMessageBoxDemo/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.Windows;
7 |
8 | namespace CustomMessageBoxDemo
9 | {
10 | ///
11 | /// Interaction logic for App.xaml
12 | ///
13 | public partial class App : Application
14 | {
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/source/CustomMessageBoxDemo/CustomMessageBox Demo.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | x86
6 | 8.0.30703
7 | 2.0
8 | {BEB8F894-9C79-4D30-8061-C5570C1B159D}
9 | WinExe
10 | Properties
11 | CustomMessageBoxDemo
12 | CustomMessageBoxDemo
13 | v4.0
14 | Client
15 | 512
16 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
17 | 4
18 |
19 |
20 | x86
21 | true
22 | full
23 | false
24 | bin\Debug\
25 | DEBUG;TRACE
26 | prompt
27 | 4
28 |
29 |
30 | x86
31 | pdbonly
32 | true
33 | bin\Release\
34 | TRACE
35 | prompt
36 | 4
37 |
38 |
39 | AnyCPU
40 | bin\Debug\
41 |
42 |
43 | AnyCPU
44 | bin\Release\
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | 4.0
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 | MSBuild:Compile
64 | Designer
65 |
66 |
67 | MSBuild:Compile
68 | Designer
69 |
70 |
71 | App.xaml
72 | Code
73 |
74 |
75 | MainWindow.xaml
76 | Code
77 |
78 |
79 |
80 |
81 | Code
82 |
83 |
84 | True
85 | True
86 | Resources.resx
87 |
88 |
89 | True
90 | Settings.settings
91 | True
92 |
93 |
94 | ResXFileCodeGenerator
95 | Resources.Designer.cs
96 |
97 |
98 |
99 | SettingsSingleFileGenerator
100 | Settings.Designer.cs
101 |
102 |
103 |
104 |
105 |
106 | {ED02D418-7C0E-4E6C-99A9-BE4357122AE7}
107 | WPFCustomMessageBox
108 |
109 |
110 |
111 |
118 |
--------------------------------------------------------------------------------
/source/CustomMessageBoxDemo/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | Standard
18 | Custom Version
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/source/CustomMessageBoxDemo/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Windows;
4 | using WPFCustomMessageBox;
5 |
6 | namespace CustomMessageBoxDemo
7 | {
8 | ///
9 | /// Interaction logic for MainWindow.xaml
10 | ///
11 | public partial class MainWindow : Window
12 | {
13 | public MainWindow()
14 | {
15 | InitializeComponent();
16 | }
17 |
18 | private void button_StandardMessage_Click(object sender, RoutedEventArgs e)
19 | {
20 | MessageBox.Show(string.Join("\n", Enumerable.Repeat("Hello World!", 12)));
21 | }
22 |
23 | private void button_StandardMessageNew_Click(object sender, RoutedEventArgs e)
24 | {
25 | CustomMessageBox.Show(string.Join("\n", Enumerable.Repeat("Hello World!", 12)));
26 | }
27 |
28 | private void button_MessageWithCaption_Click(object sender, RoutedEventArgs e)
29 | {
30 | MessageBox.Show("Hello World!", "Hello World the title.");
31 | }
32 |
33 | private void button_MessageWithCaptionNew_Click(object sender, RoutedEventArgs e)
34 | {
35 | CustomMessageBox.Show("Hello world!", "Hello World the title.");
36 | }
37 |
38 | private void button_MessageWithCaptionAndButton_Click(object sender, RoutedEventArgs e)
39 | {
40 | MessageBox.Show("Hello World!", "Hello World the title.", MessageBoxButton.OKCancel);
41 | }
42 |
43 | private void button_MessageWithCaptionAndButtonNew_Click(object sender, RoutedEventArgs e)
44 | {
45 | CustomMessageBox.Show("Hello World!", "Hello World the title.", MessageBoxButton.OKCancel);
46 | }
47 |
48 | private void button_MessageWithCaptionButtonImage_Click(object sender, RoutedEventArgs e)
49 | {
50 | MessageBox.Show(
51 | "Are you sure you want to eject the nuclear fuel rods?",
52 | "Confirm Fuel Ejection",
53 | MessageBoxButton.OKCancel,
54 | MessageBoxImage.Exclamation);
55 | }
56 |
57 | private void button_MessageWithCaptionButtonImageNew_Click(object sender, RoutedEventArgs e)
58 | {
59 | CustomMessageBox.Show("This is a message.", "This is a caption", MessageBoxButton.YesNo, MessageBoxImage.Asterisk);
60 | }
61 |
62 | private void Window_Loaded(object sender, RoutedEventArgs e)
63 | {
64 |
65 | }
66 |
67 | private void button1_Click(object sender, RoutedEventArgs e)
68 | {
69 | MessageBoxResult result = CustomMessageBox.ShowYesNoCancel(
70 | "You have unsaved changes.",
71 | "Unsaved Changes!",
72 | "Evan Wondrasek",
73 | "Don't Save",
74 | "Cancel",
75 | MessageBoxImage.Exclamation);
76 |
77 | Console.WriteLine(result);
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/source/CustomMessageBoxDemo/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 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("WPF Custom MessageBox Demo")]
11 | [assembly: AssemblyDescription("Demonstrates the functionality and usage of the WPF Custom MessageBox library.")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("CustomMessageBoxDemo")]
15 | [assembly: AssemblyCopyright("Copyright © 2012 Evan Wondrasek")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/source/CustomMessageBoxDemo/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.17379
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace CustomMessageBoxDemo.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.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 | /// Returns the cached ResourceManager instance used by this class.
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("CustomMessageBoxDemo.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
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 |
--------------------------------------------------------------------------------
/source/CustomMessageBoxDemo/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 |
--------------------------------------------------------------------------------
/source/CustomMessageBoxDemo/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.17379
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace CustomMessageBoxDemo.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.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 |
--------------------------------------------------------------------------------
/source/CustomMessageBoxDemo/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/source/CustomMessageBoxDemo/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/source/WPFCustomMessageBox.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual Studio 2010
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPFCustomMessageBox", "WPFCustomMessageBox\WPFCustomMessageBox.csproj", "{ED02D418-7C0E-4E6C-99A9-BE4357122AE7}"
5 | EndProject
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomMessageBox Demo", "CustomMessageBoxDemo\CustomMessageBox Demo.csproj", "{BEB8F894-9C79-4D30-8061-C5570C1B159D}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Debug|x86 = Debug|x86
12 | Release|Any CPU = Release|Any CPU
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {ED02D418-7C0E-4E6C-99A9-BE4357122AE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {ED02D418-7C0E-4E6C-99A9-BE4357122AE7}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {ED02D418-7C0E-4E6C-99A9-BE4357122AE7}.Debug|x86.ActiveCfg = Debug|x86
19 | {ED02D418-7C0E-4E6C-99A9-BE4357122AE7}.Debug|x86.Build.0 = Debug|x86
20 | {ED02D418-7C0E-4E6C-99A9-BE4357122AE7}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {ED02D418-7C0E-4E6C-99A9-BE4357122AE7}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {ED02D418-7C0E-4E6C-99A9-BE4357122AE7}.Release|x86.ActiveCfg = Release|x86
23 | {ED02D418-7C0E-4E6C-99A9-BE4357122AE7}.Release|x86.Build.0 = Release|x86
24 | {BEB8F894-9C79-4D30-8061-C5570C1B159D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 | {BEB8F894-9C79-4D30-8061-C5570C1B159D}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 | {BEB8F894-9C79-4D30-8061-C5570C1B159D}.Debug|x86.ActiveCfg = Debug|x86
27 | {BEB8F894-9C79-4D30-8061-C5570C1B159D}.Debug|x86.Build.0 = Debug|x86
28 | {BEB8F894-9C79-4D30-8061-C5570C1B159D}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {BEB8F894-9C79-4D30-8061-C5570C1B159D}.Release|Any CPU.Build.0 = Release|Any CPU
30 | {BEB8F894-9C79-4D30-8061-C5570C1B159D}.Release|x86.ActiveCfg = Release|x86
31 | {BEB8F894-9C79-4D30-8061-C5570C1B159D}.Release|x86.Build.0 = Release|x86
32 | EndGlobalSection
33 | GlobalSection(SolutionProperties) = preSolution
34 | HideSolutionNode = FALSE
35 | EndGlobalSection
36 | EndGlobal
37 |
--------------------------------------------------------------------------------
/source/WPFCustomMessageBox/App.xaml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/source/WPFCustomMessageBox/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.Windows;
7 |
8 | namespace WPFCustomButtonDialogs
9 | {
10 | ///
11 | /// Interaction logic for App.xaml
12 | ///
13 | public partial class App : Application
14 | {
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/source/WPFCustomMessageBox/CustomMessageBox.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // TODO: Update copyright text.
4 | //
5 | // -----------------------------------------------------------------------
6 |
7 | namespace WPFCustomMessageBox
8 | {
9 | using System.Windows;
10 |
11 | ///
12 | /// Displays a message box.
13 | ///
14 | public static class CustomMessageBox
15 | {
16 | ///
17 | /// Displays a message box that has a message and returns a result.
18 | ///
19 | /// A System.String that specifies the text to display.
20 | /// A System.Windows.MessageBoxResult value that specifies which message box button is clicked by the user.
21 | public static MessageBoxResult Show(string messageBoxText)
22 | {
23 | var msgData = new MessageBoxData()
24 | {
25 | Message = messageBoxText
26 | };
27 |
28 | return msgData.ShowMessageBox();
29 | }
30 |
31 | ///
32 | /// Displays a message box that has a message and a title bar caption; and that returns a result.
33 | ///
34 | /// A System.String that specifies the text to display.
35 | /// A System.String that specifies the title bar caption to display.
36 | /// A System.Windows.MessageBoxResult value that specifies which message box button is clicked by the user.
37 | public static MessageBoxResult Show(string messageBoxText, string caption)
38 | {
39 | var msgData = new MessageBoxData()
40 | {
41 | Message = messageBoxText,
42 | Caption = caption
43 | };
44 |
45 | return msgData.ShowMessageBox();
46 | }
47 |
48 | ///
49 | /// Displays a message box in front of the specified window. The message box displays a message and returns a result.
50 | ///
51 | /// A System.Windows.Window that represents the owner window of the message box.
52 | /// A System.String that specifies the text to display.
53 | /// A System.Windows.MessageBoxResult value that specifies which message box button is clicked by the user.
54 | public static MessageBoxResult Show(Window owner, string messageBoxText)
55 | {
56 | var msgData = new MessageBoxData()
57 | {
58 | Message = messageBoxText,
59 | Owner = owner
60 | };
61 |
62 | return msgData.ShowMessageBox();
63 | }
64 |
65 | ///
66 | /// Displays a message box in front of the specified window. The message box displays a message and title bar caption; and it returns a result.
67 | ///
68 | /// A System.Windows.Window that represents the owner window of the message box.
69 | /// A System.String that specifies the text to display.
70 | /// A System.String that specifies the title bar caption to display.
71 | /// A System.Windows.MessageBoxResult value that specifies which message box button is clicked by the user.
72 | public static MessageBoxResult Show(Window owner, string messageBoxText, string caption)
73 | {
74 | var msgData = new MessageBoxData()
75 | {
76 | Message = messageBoxText,
77 | Caption = caption,
78 | Owner = owner
79 | };
80 |
81 | return msgData.ShowMessageBox();
82 | }
83 |
84 | ///
85 | /// Displays a message box that has a message, title bar caption, and button; and that returns a result.
86 | ///
87 | /// A System.String that specifies the text to display.
88 | /// A System.String that specifies the title bar caption to display.
89 | /// A System.Windows.MessageBoxButton value that specifies which button or buttons to display.
90 | /// A System.Windows.MessageBoxResult value that specifies which message box button is clicked by the user.
91 | public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button)
92 | {
93 | var msgData = new MessageBoxData()
94 | {
95 | Message = messageBoxText,
96 | Caption = caption,
97 | Buttons = button
98 | };
99 |
100 | return msgData.ShowMessageBox();
101 | }
102 |
103 | ///
104 | /// Displays a message box that has a message, title bar caption, button, and icon; and that returns a result.
105 | ///
106 | /// A System.String that specifies the text to display.
107 | /// A System.String that specifies the title bar caption to display.
108 | /// A System.Windows.MessageBoxButton value that specifies which button or buttons to display.
109 | /// A System.Windows.MessageBoxImage value that specifies the icon to display.
110 | /// A System.Windows.MessageBoxResult value that specifies which message box button is clicked by the user.
111 | public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button, MessageBoxImage icon)
112 | {
113 | var msgData = new MessageBoxData()
114 | {
115 | Message = messageBoxText,
116 | Caption = caption,
117 | Buttons = button,
118 | Image = icon
119 | };
120 |
121 | return msgData.ShowMessageBox();
122 | }
123 |
124 | ///
125 | /// Displays a message box that has a message, title bar caption, and OK button with a custom System.String value for the button's text; and that returns a result.
126 | ///
127 | /// A System.String that specifies the text to display.
128 | /// A System.String that specifies the title bar caption to display.
129 | /// A System.String that specifies the text to display within the OK button.
130 | /// A System.Windows.MessageBoxResult value that specifies which message box button is clicked by the user.
131 | public static MessageBoxResult ShowOK(string messageBoxText, string caption, string okButtonText)
132 | {
133 | var msgData = new MessageBoxData()
134 | {
135 | Message = messageBoxText,
136 | Caption = caption,
137 | Buttons = MessageBoxButton.YesNoCancel,
138 | OkButtonCaption = okButtonText
139 | };
140 |
141 | return msgData.ShowMessageBox();
142 | }
143 |
144 | ///
145 | /// Displays a message box that has a message, title bar caption, OK button with a custom System.String value for the button's text, and icon; and that returns a result.
146 | ///
147 | /// A System.String that specifies the text to display.
148 | /// A System.String that specifies the title bar caption to display.
149 | /// A System.String that specifies the text to display within the OK button.
150 | /// A System.Windows.MessageBoxImage value that specifies the icon to display.
151 | /// A System.Windows.MessageBoxResult value that specifies which message box button is clicked by the user.
152 | public static MessageBoxResult ShowOK(string messageBoxText, string caption, string okButtonText, MessageBoxImage icon)
153 | {
154 | var msgData = new MessageBoxData()
155 | {
156 | Message = messageBoxText,
157 | Caption = caption,
158 | Buttons = MessageBoxButton.OK,
159 | Image = icon,
160 | OkButtonCaption = okButtonText
161 | };
162 |
163 | return msgData.ShowMessageBox();
164 | }
165 |
166 | ///
167 | /// Displays a message box that has a message, caption, and OK/Cancel buttons with custom System.String values for the buttons' text;
168 | /// and that returns a result.
169 | ///
170 | /// A System.String that specifies the text to display.
171 | /// A System.String that specifies the title bar caption to display.
172 | /// A System.String that specifies the text to display within the OK button.
173 | /// A System.String that specifies the text to display within the Cancel button.
174 | /// A System.Windows.MessageBoxResult value that specifies which message box button is clicked by the user.
175 | public static MessageBoxResult ShowOKCancel(string messageBoxText, string caption, string okButtonText, string cancelButtonText)
176 | {
177 | var msgData = new MessageBoxData()
178 | {
179 | Message = messageBoxText,
180 | Caption = caption,
181 | Buttons = MessageBoxButton.OKCancel,
182 | OkButtonCaption = okButtonText,
183 | CancelButtonCaption = cancelButtonText
184 | };
185 |
186 | return msgData.ShowMessageBox();
187 | }
188 |
189 | ///
190 | /// Displays a message box that has a message, caption, OK/Cancel buttons with custom System.String values for the buttons' text, and icon;
191 | /// and that returns a result.
192 | ///
193 | /// A System.String that specifies the text to display.
194 | /// A System.String that specifies the title bar caption to display.
195 | /// A System.String that specifies the text to display within the OK button.
196 | /// A System.String that specifies the text to display within the Cancel button.
197 | /// A System.Windows.MessageBoxImage value that specifies the icon to display.
198 | /// A System.Windows.MessageBoxResult value that specifies which message box button is clicked by the user.
199 | public static MessageBoxResult ShowOKCancel(string messageBoxText, string caption, string okButtonText, string cancelButtonText, MessageBoxImage icon)
200 | {
201 | var msgData = new MessageBoxData()
202 | {
203 | Message = messageBoxText,
204 | Caption = caption,
205 | Buttons = MessageBoxButton.OKCancel,
206 | Image = icon,
207 | OkButtonCaption = okButtonText,
208 | CancelButtonCaption = cancelButtonText
209 | };
210 |
211 | return msgData.ShowMessageBox();
212 | }
213 |
214 | ///
215 | /// Displays a message box that has a message, caption, and Yes/No buttons with custom System.String values for the buttons' text;
216 | /// and that returns a result.
217 | ///
218 | /// A System.String that specifies the text to display.
219 | /// A System.String that specifies the title bar caption to display.
220 | /// A System.String that specifies the text to display within the Yes button.
221 | /// A System.String that specifies the text to display within the No button.
222 | /// A System.Windows.MessageBoxResult value that specifies which message box button is clicked by the user.
223 | public static MessageBoxResult ShowYesNo(string messageBoxText, string caption, string yesButtonText, string noButtonText)
224 | {
225 | var msgData = new MessageBoxData()
226 | {
227 | Message = messageBoxText,
228 | Caption = caption,
229 | Buttons = MessageBoxButton.YesNo,
230 | YesButtonCaption = yesButtonText,
231 | NoButtonCaption = noButtonText
232 | };
233 |
234 | return msgData.ShowMessageBox();
235 | }
236 |
237 | ///
238 | /// Displays a message box that has a message, caption, Yes/No buttons with custom System.String values for the buttons' text, and icon;
239 | /// and that returns a result.
240 | ///
241 | /// A System.String that specifies the text to display.
242 | /// A System.String that specifies the title bar caption to display.
243 | /// A System.String that specifies the text to display within the Yes button.
244 | /// A System.String that specifies the text to display within the No button.
245 | /// A System.Windows.MessageBoxImage value that specifies the icon to display.
246 | /// A System.Windows.MessageBoxResult value that specifies which message box button is clicked by the user.
247 | public static MessageBoxResult ShowYesNo(string messageBoxText, string caption, string yesButtonText, string noButtonText, MessageBoxImage icon)
248 | {
249 | var msgData = new MessageBoxData()
250 | {
251 | Message = messageBoxText,
252 | Caption = caption,
253 | Buttons = MessageBoxButton.YesNo,
254 | Image = icon,
255 | YesButtonCaption = yesButtonText,
256 | NoButtonCaption = noButtonText
257 | };
258 |
259 | return msgData.ShowMessageBox();
260 | }
261 |
262 | ///
263 | /// Displays a message box that has a message, caption, and Yes/No/Cancel buttons with custom System.String values for the buttons' text;
264 | /// and that returns a result.
265 | ///
266 | /// A System.String that specifies the text to display.
267 | /// A System.String that specifies the title bar caption to display.
268 | /// A System.String that specifies the text to display within the Yes button.
269 | /// A System.String that specifies the text to display within the No button.
270 | /// A System.String that specifies the text to display within the Cancel button.
271 | /// A System.Windows.MessageBoxResult value that specifies which message box button is clicked by the user.
272 | public static MessageBoxResult ShowYesNoCancel(string messageBoxText, string caption, string yesButtonText, string noButtonText, string cancelButtonText)
273 | {
274 | var msgData = new MessageBoxData()
275 | {
276 | Message = messageBoxText,
277 | Caption = caption,
278 | Buttons = MessageBoxButton.YesNoCancel,
279 | YesButtonCaption = yesButtonText,
280 | NoButtonCaption = noButtonText,
281 | CancelButtonCaption = cancelButtonText
282 | };
283 |
284 | return msgData.ShowMessageBox();
285 | }
286 |
287 | ///
288 | /// Displays a message box that has a message, caption, Yes/No/Cancel buttons with custom System.String values for the buttons' text, and icon;
289 | /// and that returns a result.
290 | ///
291 | /// A System.String that specifies the text to display.
292 | /// A System.String that specifies the title bar caption to display.
293 | /// A System.String that specifies the text to display within the Yes button.
294 | /// A System.String that specifies the text to display within the No button.
295 | /// A System.String that specifies the text to display within the Cancel button.
296 | /// A System.Windows.MessageBoxImage value that specifies the icon to display.
297 | /// A System.Windows.MessageBoxResult value that specifies which message box button is clicked by the user.
298 | public static MessageBoxResult ShowYesNoCancel(string messageBoxText, string caption, string yesButtonText, string noButtonText, string cancelButtonText, MessageBoxImage icon)
299 | {
300 | var msgData = new MessageBoxData()
301 | {
302 | Message = messageBoxText,
303 | Caption = caption,
304 | Buttons = MessageBoxButton.YesNoCancel,
305 | Image = icon,
306 | YesButtonCaption = yesButtonText,
307 | NoButtonCaption = noButtonText,
308 | CancelButtonCaption = cancelButtonText
309 | };
310 |
311 | return msgData.ShowMessageBox();
312 | }
313 | }
314 | }
315 |
--------------------------------------------------------------------------------
/source/WPFCustomMessageBox/CustomMessageBoxWindow.xaml:
--------------------------------------------------------------------------------
1 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
33 |
34 |
35 |
36 |
40 |
41 |
42 |
43 |
47 |
48 |
49 |
50 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/source/WPFCustomMessageBox/CustomMessageBoxWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System.Drawing;
2 | using System.Windows;
3 |
4 | namespace WPFCustomMessageBox
5 | {
6 | ///
7 | /// Interaction logic for ModalDialog.xaml
8 | ///
9 | internal partial class CustomMessageBoxWindow : Window
10 | {
11 | #region Properties
12 |
13 | internal string Caption
14 | {
15 | get
16 | {
17 | return this.Title;
18 | }
19 | set
20 | {
21 | this.Title = value;
22 | }
23 | }
24 |
25 | internal string Message
26 | {
27 | get
28 | {
29 | return this.TextBlock_Message.Text;
30 | }
31 | set
32 | {
33 | this.TextBlock_Message.Text = value;
34 | }
35 | }
36 |
37 | internal string OkButtonText
38 | {
39 | get
40 | {
41 | return this.Label_Ok.Content.ToString();
42 | }
43 | set
44 | {
45 | this.Label_Ok.Content = value.TryAddKeyboardAccellerator();
46 | }
47 | }
48 |
49 | internal string CancelButtonText
50 | {
51 | get
52 | {
53 | return this.Label_Cancel.Content.ToString();
54 | }
55 | set
56 | {
57 | this.Label_Cancel.Content = value.TryAddKeyboardAccellerator();
58 | }
59 | }
60 |
61 | internal string YesButtonText
62 | {
63 | get
64 | {
65 | return this.Label_Yes.Content.ToString();
66 | }
67 | set
68 | {
69 | this.Label_Yes.Content = value.TryAddKeyboardAccellerator();
70 | }
71 | }
72 |
73 | internal string NoButtonText
74 | {
75 | get
76 | {
77 | return this.Label_No.Content.ToString();
78 | }
79 | set
80 | {
81 | this.Label_No.Content = value.TryAddKeyboardAccellerator();
82 | }
83 | }
84 |
85 | public MessageBoxResult Result { get; set; }
86 |
87 | #endregion
88 |
89 | #region Constructor
90 |
91 | internal CustomMessageBoxWindow(string message, string caption, MessageBoxButton button, MessageBoxImage image)
92 | {
93 | this.InitializeComponent();
94 |
95 | this.Message = message;
96 | this.Caption = caption;
97 | this.Image_MessageBox.Visibility = Visibility.Collapsed;
98 |
99 | this.DisplayImage(image);
100 | this.DisplayButtons(button);
101 | }
102 |
103 | #endregion
104 |
105 | #region Methods
106 |
107 | private void DisplayButtons(MessageBoxButton button)
108 | {
109 | switch (button)
110 | {
111 | case MessageBoxButton.OKCancel:
112 | // Hide all but OK, Cancel
113 | this.Button_OK.Visibility = System.Windows.Visibility.Visible;
114 | this.Button_OK.Focus();
115 | this.Button_Cancel.Visibility = System.Windows.Visibility.Visible;
116 |
117 | this.Button_Yes.Visibility = System.Windows.Visibility.Collapsed;
118 | this.Button_No.Visibility = System.Windows.Visibility.Collapsed;
119 | break;
120 |
121 | case MessageBoxButton.YesNo:
122 | // Hide all but Yes, No
123 | this.Button_Yes.Visibility = System.Windows.Visibility.Visible;
124 | this.Button_Yes.Focus();
125 | this.Button_No.Visibility = System.Windows.Visibility.Visible;
126 |
127 | this.Button_OK.Visibility = System.Windows.Visibility.Collapsed;
128 | this.Button_Cancel.Visibility = System.Windows.Visibility.Collapsed;
129 | break;
130 |
131 | case MessageBoxButton.YesNoCancel:
132 | // Hide only OK
133 | this.Button_Yes.Visibility = System.Windows.Visibility.Visible;
134 | this.Button_Yes.Focus();
135 | this.Button_No.Visibility = System.Windows.Visibility.Visible;
136 | this.Button_Cancel.Visibility = System.Windows.Visibility.Visible;
137 |
138 | this.Button_OK.Visibility = System.Windows.Visibility.Collapsed;
139 | break;
140 |
141 | default:
142 | // Hide all but OK
143 | this.Button_OK.Visibility = System.Windows.Visibility.Visible;
144 | this.Button_OK.Focus();
145 |
146 | this.Button_Yes.Visibility = System.Windows.Visibility.Collapsed;
147 | this.Button_No.Visibility = System.Windows.Visibility.Collapsed;
148 | this.Button_Cancel.Visibility = System.Windows.Visibility.Collapsed;
149 | break;
150 | }
151 | }
152 |
153 | private void DisplayImage(MessageBoxImage image)
154 | {
155 | Icon icon;
156 |
157 | switch (image)
158 | {
159 | case MessageBoxImage.None:
160 | return;
161 |
162 | case MessageBoxImage.Exclamation: // Enumeration value 48 - also covers "Warning"
163 | icon = SystemIcons.Exclamation;
164 | break;
165 |
166 | case MessageBoxImage.Error: // Enumeration value 16, also covers "Hand" and "Stop"
167 | icon = SystemIcons.Hand;
168 | break;
169 |
170 | case MessageBoxImage.Information: // Enumeration value 64 - also covers "Asterisk"
171 | icon = SystemIcons.Information;
172 | break;
173 |
174 | case MessageBoxImage.Question:
175 | icon = SystemIcons.Question;
176 | break;
177 |
178 | default:
179 | icon = SystemIcons.Information;
180 | break;
181 | }
182 |
183 | this.Image_MessageBox.Source = icon.ToImageSource();
184 | this.Image_MessageBox.Visibility = Visibility.Visible;
185 | }
186 |
187 | private void Button_OK_Click(object sender, RoutedEventArgs e)
188 | {
189 | this.Result = MessageBoxResult.OK;
190 | this.Close();
191 | }
192 |
193 | private void Button_Cancel_Click(object sender, RoutedEventArgs e)
194 | {
195 | this.Result = MessageBoxResult.Cancel;
196 | this.Close();
197 | }
198 |
199 | private void Button_Yes_Click(object sender, RoutedEventArgs e)
200 | {
201 | this.Result = MessageBoxResult.Yes;
202 | this.Close();
203 | }
204 |
205 | private void Button_No_Click(object sender, RoutedEventArgs e)
206 | {
207 | this.Result = MessageBoxResult.No;
208 | this.Close();
209 | }
210 |
211 | #endregion
212 | }
213 | }
214 |
--------------------------------------------------------------------------------
/source/WPFCustomMessageBox/MessageBoxData.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Windows;
3 |
4 | namespace WPFCustomMessageBox
5 | {
6 | internal class MessageBoxData
7 | {
8 | #region Properties
9 |
10 | public Window Owner { get; set; }
11 |
12 | public string Message { get; set; } = "";
13 |
14 | public string Caption { get; set; } = "Message";
15 |
16 | public MessageBoxButton Buttons { get; set; } = MessageBoxButton.OK;
17 |
18 | public MessageBoxImage Image { get; set; } = MessageBoxImage.None;
19 |
20 | public string YesButtonCaption { get; set; }
21 |
22 | public string NoButtonCaption { get; set; }
23 |
24 | public string CancelButtonCaption { get; set; }
25 |
26 | public string OkButtonCaption { get; set; }
27 |
28 | public MessageBoxResult Result { get; set; } = MessageBoxResult.None;
29 |
30 | #endregion
31 |
32 | #region Methods
33 |
34 | ///
35 | /// Displays a message box that is defined by the properties of this class.
36 | /// In case the current thread is not a STA thread already,
37 | /// a new STA thread is being created and the MessageBox is being displayed from there.
38 | ///
39 | ///
40 | public MessageBoxResult ShowMessageBox()
41 | {
42 | if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
43 | {
44 | this.ShowMessageBoxSTA();
45 | }
46 | else
47 | {
48 | var thread = new Thread(this.ShowMessageBoxSTA);
49 | thread.SetApartmentState(ApartmentState.STA);
50 | thread.Start();
51 | thread.Join();
52 | }
53 |
54 | return this.Result;
55 | }
56 |
57 | private void ShowMessageBoxSTA()
58 | {
59 | var msg = new CustomMessageBoxWindow(this.Message, this.Caption, this.Buttons, this.Image);
60 |
61 | msg.YesButtonText = this.YesButtonCaption ?? msg.YesButtonText;
62 | msg.NoButtonText = this.NoButtonCaption ?? msg.NoButtonText;
63 | msg.CancelButtonText = this.CancelButtonCaption ?? msg.CancelButtonText;
64 | msg.OkButtonText = this.OkButtonCaption ?? msg.OkButtonText;
65 | msg.Owner = this.Owner ?? msg.Owner;
66 |
67 | msg.ShowDialog();
68 |
69 | this.Result = msg.Result;
70 | }
71 |
72 | #endregion
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/source/WPFCustomMessageBox/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 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("WPFCustomMessageBox")]
11 | [assembly: AssemblyDescription("A WPF clone of the native Windows MessageBox with extra customizations like custom button text.")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("WPFCustomMessageBox")]
15 | [assembly: AssemblyCopyright("Copyright © 2013 Evan Wondrasek / Apricity Software LLC")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.7.*")]
55 | //[assembly: AssemblyFileVersion("1.0.5.0")]
56 |
--------------------------------------------------------------------------------
/source/WPFCustomMessageBox/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.17929
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace WPFCustomMessageBox.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.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 | /// Returns the cached ResourceManager instance used by this class.
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("WPFCustomMessageBox.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
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 |
--------------------------------------------------------------------------------
/source/WPFCustomMessageBox/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 |
--------------------------------------------------------------------------------
/source/WPFCustomMessageBox/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.17929
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace WPFCustomMessageBox.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.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 |
--------------------------------------------------------------------------------
/source/WPFCustomMessageBox/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/source/WPFCustomMessageBox/Util.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // TODO: Update copyright text.
4 | //
5 | // -----------------------------------------------------------------------
6 |
7 | namespace WPFCustomMessageBox
8 | {
9 | using System.Drawing;
10 | using System.Windows;
11 | using System.Windows.Interop;
12 | using System.Windows.Media;
13 | using System.Windows.Media.Imaging;
14 |
15 | ///
16 | /// TODO: Update summary.
17 | ///
18 | internal static class Util
19 | {
20 | internal static ImageSource ToImageSource(this Icon icon)
21 | {
22 | ImageSource imageSource = Imaging.CreateBitmapSourceFromHIcon(
23 | icon.Handle,
24 | Int32Rect.Empty,
25 | BitmapSizeOptions.FromEmptyOptions());
26 |
27 | return imageSource;
28 | }
29 |
30 | ///
31 | /// Keyboard Accellerators are used in Windows to allow easy shortcuts to controls like Buttons and
32 | /// MenuItems. These allow users to press the Alt key, and a shortcut key will be highlighted on the
33 | /// control. If the user presses that key, that control will be activated.
34 | /// This method checks a string if it contains a keyboard accellerator. If it doesn't, it adds one to the
35 | /// beginning of the string. If there are two strings with the same accellerator, Windows handles it.
36 | /// The keyboard accellerator character for WPF is underscore (_). It will not be visible.
37 | ///
38 | ///
39 | ///
40 | internal static string TryAddKeyboardAccellerator(this string input)
41 | {
42 | const string accellerator = "_"; // This is the default WPF accellerator symbol - used to be & in WinForms
43 |
44 | // If it already contains an accellerator, do nothing
45 | if (input.Contains(accellerator)) return input;
46 |
47 | return accellerator + input;
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/source/WPFCustomMessageBox/WPFCustomMessageBox.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | x86
6 | 8.0.30703
7 | 2.0
8 | {ED02D418-7C0E-4E6C-99A9-BE4357122AE7}
9 | Library
10 | Properties
11 | WPFCustomMessageBox
12 | WPFCustomMessageBox
13 | v4.0
14 | Client
15 | 512
16 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
17 | 4
18 |
19 |
20 | x86
21 | true
22 | full
23 | false
24 | bin\Debug\
25 | DEBUG;TRACE
26 | prompt
27 | 4
28 |
29 |
30 | x86
31 | pdbonly
32 | true
33 | bin\Release\
34 | TRACE
35 | prompt
36 | 4
37 |
38 |
39 |
40 |
41 |
42 | blankicon.ico
43 |
44 |
45 | AnyCPU
46 | bin\Debug\
47 | bin\Debug\WPFCustomMessageBox.XML
48 |
49 |
50 | AnyCPU
51 | bin\Release\
52 | bin\Release\WPFCustomMessageBox.XML
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | 4.0
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 | CustomMessageBoxWindow.xaml
69 |
70 |
71 |
72 |
73 |
74 | Designer
75 | MSBuild:Compile
76 |
77 |
78 |
79 |
80 | Code
81 |
82 |
83 | True
84 | True
85 | Resources.resx
86 |
87 |
88 | True
89 | Settings.settings
90 | True
91 |
92 |
93 | ResXFileCodeGenerator
94 | Resources.Designer.cs
95 |
96 |
97 | SettingsSingleFileGenerator
98 | Settings.Designer.cs
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
113 |
--------------------------------------------------------------------------------
/source/WPFCustomMessageBox/blankicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/evanwon/WPFCustomMessageBox/b1ac17557accbd09649c9b3c0d5eca42e15bccc1/source/WPFCustomMessageBox/blankicon.ico
--------------------------------------------------------------------------------