├── .gitattributes
├── .gitignore
├── Docs
├── Screenshots
│ ├── CriticalDialog.png
│ ├── Demo.gif
│ ├── ErrorDialog.png
│ ├── InformationDialog.png
│ ├── InputDialog.png
│ ├── ProgressDialogs.gif
│ ├── SuccessDialog.png
│ └── WarningDialog.png
└── logo.png
├── LICENSE
├── README.md
├── SimpleDialogs.Demo
├── App.config
├── App.xaml
├── App.xaml.cs
├── FodyWeavers.xml
├── Helpers
│ ├── MarginSetterHelper.cs
│ └── SpacingHelper.cs
├── MainWindow.xaml
├── MainWindow.xaml.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── Resources
│ └── logo.png
├── SimpleDialogs.Demo.csproj
├── ViewModel
│ ├── MainViewModel.cs
│ └── ViewModelLocator.cs
├── icon.ico
└── packages.config
├── SimpleDialogs.sln
└── SimpleDialogs
├── Commands
└── SimpleCommand.cs
├── Controls
├── BaseDialog.cs
├── DialogButtonClickedEventArgs.cs
├── DialogClosedEventArgs.cs
├── DialogContainer.cs
├── InputDialog.cs
├── MessageDialog.cs
├── ProgressDialog.cs
└── ProgressRing.cs
├── Design
├── BaseDialog.xaml
├── DialogContainer.xaml
├── InputDialog.xaml
├── MessageDialog.xaml
├── ProgressDialog.xaml
└── ProgressRing.xaml
├── DialogManager.cs
├── Enumerators
├── DialogButton.cs
└── MessageSeverity.cs
├── Helpers
└── KeyboardHelper.cs
├── Properties
├── AssemblyInfo.cs
├── Resources.Designer.cs
├── Resources.resx
├── Settings.Designer.cs
└── Settings.settings
├── Resources
└── SquareButtonStyle.xaml
├── SimpleDialogs.csproj
├── SimpleDialogs.nuspec
├── TemplateSelectors
└── MessageDialogIconSelector.cs
├── Themes
├── Dark.xaml
├── DefaultColors.xaml
├── Generic.xaml
└── Light.xaml
└── ValueConverters
├── BoolToVisibilityConverter.cs
├── NullToVisibilityConverter.cs
└── PercentageConverter.cs
/.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 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # MSTest test Results
33 | [Tt]est[Rr]esult*/
34 | [Bb]uild[Ll]og.*
35 |
36 | # NUNIT
37 | *.VisualState.xml
38 | TestResult.xml
39 |
40 | # Build Results of an ATL Project
41 | [Dd]ebugPS/
42 | [Rr]eleasePS/
43 | dlldata.c
44 |
45 | # .NET Core
46 | project.lock.json
47 | project.fragment.lock.json
48 | artifacts/
49 | **/Properties/launchSettings.json
50 |
51 | *_i.c
52 | *_p.c
53 | *_i.h
54 | *.ilk
55 | *.meta
56 | *.obj
57 | *.pch
58 | *.pdb
59 | *.pgc
60 | *.pgd
61 | *.rsp
62 | *.sbr
63 | *.tlb
64 | *.tli
65 | *.tlh
66 | *.tmp
67 | *.tmp_proj
68 | *.log
69 | *.vspscc
70 | *.vssscc
71 | .builds
72 | *.pidb
73 | *.svclog
74 | *.scc
75 |
76 | # Chutzpah Test files
77 | _Chutzpah*
78 |
79 | # Visual C++ cache files
80 | ipch/
81 | *.aps
82 | *.ncb
83 | *.opendb
84 | *.opensdf
85 | *.sdf
86 | *.cachefile
87 | *.VC.db
88 | *.VC.VC.opendb
89 |
90 | # Visual Studio profiler
91 | *.psess
92 | *.vsp
93 | *.vspx
94 | *.sap
95 |
96 | # TFS 2012 Local Workspace
97 | $tf/
98 |
99 | # Guidance Automation Toolkit
100 | *.gpState
101 |
102 | # ReSharper is a .NET coding add-in
103 | _ReSharper*/
104 | *.[Rr]e[Ss]harper
105 | *.DotSettings.user
106 |
107 | # JustCode is a .NET coding add-in
108 | .JustCode
109 |
110 | # TeamCity is a build add-in
111 | _TeamCity*
112 |
113 | # DotCover is a Code Coverage Tool
114 | *.dotCover
115 |
116 | # Visual Studio code coverage results
117 | *.coverage
118 | *.coveragexml
119 |
120 | # NCrunch
121 | _NCrunch_*
122 | .*crunch*.local.xml
123 | nCrunchTemp_*
124 |
125 | # MightyMoose
126 | *.mm.*
127 | AutoTest.Net/
128 |
129 | # Web workbench (sass)
130 | .sass-cache/
131 |
132 | # Installshield output folder
133 | [Ee]xpress/
134 |
135 | # DocProject is a documentation generator add-in
136 | DocProject/buildhelp/
137 | DocProject/Help/*.HxT
138 | DocProject/Help/*.HxC
139 | DocProject/Help/*.hhc
140 | DocProject/Help/*.hhk
141 | DocProject/Help/*.hhp
142 | DocProject/Help/Html2
143 | DocProject/Help/html
144 |
145 | # Click-Once directory
146 | publish/
147 |
148 | # Publish Web Output
149 | *.[Pp]ublish.xml
150 | *.azurePubxml
151 | # TODO: Comment the next line if you want to checkin your web deploy settings
152 | # but database connection strings (with potential passwords) will be unencrypted
153 | *.pubxml
154 | *.publishproj
155 |
156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
157 | # checkin your Azure Web App publish settings, but sensitive information contained
158 | # in these scripts will be unencrypted
159 | PublishScripts/
160 |
161 | # NuGet Packages
162 | *.nupkg
163 | # The packages folder can be ignored because of Package Restore
164 | **/packages/*
165 | # except build/, which is used as an MSBuild target.
166 | !**/packages/build/
167 | # Uncomment if necessary however generally it will be regenerated when needed
168 | #!**/packages/repositories.config
169 | # NuGet v3's project.json files produces more ignorable files
170 | *.nuget.props
171 | *.nuget.targets
172 |
173 | # Microsoft Azure Build Output
174 | csx/
175 | *.build.csdef
176 |
177 | # Microsoft Azure Emulator
178 | ecf/
179 | rcf/
180 |
181 | # Windows Store app package directories and files
182 | AppPackages/
183 | BundleArtifacts/
184 | Package.StoreAssociation.xml
185 | _pkginfo.txt
186 |
187 | # Visual Studio cache files
188 | # files ending in .cache can be ignored
189 | *.[Cc]ache
190 | # but keep track of directories ending in .cache
191 | !*.[Cc]ache/
192 |
193 | # Others
194 | ClientBin/
195 | ~$*
196 | *~
197 | *.dbmdl
198 | *.dbproj.schemaview
199 | *.jfm
200 | *.pfx
201 | *.publishsettings
202 | orleans.codegen.cs
203 |
204 | # Since there are multiple workflows, uncomment next line to ignore bower_components
205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
206 | #bower_components/
207 |
208 | # RIA/Silverlight projects
209 | Generated_Code/
210 |
211 | # Backup & report files from converting an old project file
212 | # to a newer Visual Studio version. Backup files are not needed,
213 | # because we have git ;-)
214 | _UpgradeReport_Files/
215 | Backup*/
216 | UpgradeLog*.XML
217 | UpgradeLog*.htm
218 |
219 | # SQL Server files
220 | *.mdf
221 | *.ldf
222 | *.ndf
223 |
224 | # Business Intelligence projects
225 | *.rdl.data
226 | *.bim.layout
227 | *.bim_*.settings
228 |
229 | # Microsoft Fakes
230 | FakesAssemblies/
231 |
232 | # GhostDoc plugin setting file
233 | *.GhostDoc.xml
234 |
235 | # Node.js Tools for Visual Studio
236 | .ntvs_analysis.dat
237 | node_modules/
238 |
239 | # Typescript v1 declaration files
240 | typings/
241 |
242 | # Visual Studio 6 build log
243 | *.plg
244 |
245 | # Visual Studio 6 workspace options file
246 | *.opt
247 |
248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
249 | *.vbw
250 |
251 | # Visual Studio LightSwitch build output
252 | **/*.HTMLClient/GeneratedArtifacts
253 | **/*.DesktopClient/GeneratedArtifacts
254 | **/*.DesktopClient/ModelManifest.xml
255 | **/*.Server/GeneratedArtifacts
256 | **/*.Server/ModelManifest.xml
257 | _Pvt_Extensions
258 |
259 | # Paket dependency manager
260 | .paket/paket.exe
261 | paket-files/
262 |
263 | # FAKE - F# Make
264 | .fake/
265 |
266 | # JetBrains Rider
267 | .idea/
268 | *.sln.iml
269 |
270 | # CodeRush
271 | .cr/
272 |
273 | # Python Tools for Visual Studio (PTVS)
274 | __pycache__/
275 | *.pyc
276 |
277 | # Cake - Uncomment if you are using it
278 | # tools/**
279 | # !tools/packages.config
280 |
281 | # Telerik's JustMock configuration file
282 | *.jmconfig
283 |
284 | # BizTalk build output
285 | *.btp.cs
286 | *.btm.cs
287 | *.odx.cs
288 | *.xsd.cs
289 | SimpleDialogs/nuget.exe
290 |
--------------------------------------------------------------------------------
/Docs/Screenshots/CriticalDialog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/schdck/SimpleDialogs/d5bdc4ac9599e8b59ee739ce6fcf42f610b4e6e4/Docs/Screenshots/CriticalDialog.png
--------------------------------------------------------------------------------
/Docs/Screenshots/Demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/schdck/SimpleDialogs/d5bdc4ac9599e8b59ee739ce6fcf42f610b4e6e4/Docs/Screenshots/Demo.gif
--------------------------------------------------------------------------------
/Docs/Screenshots/ErrorDialog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/schdck/SimpleDialogs/d5bdc4ac9599e8b59ee739ce6fcf42f610b4e6e4/Docs/Screenshots/ErrorDialog.png
--------------------------------------------------------------------------------
/Docs/Screenshots/InformationDialog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/schdck/SimpleDialogs/d5bdc4ac9599e8b59ee739ce6fcf42f610b4e6e4/Docs/Screenshots/InformationDialog.png
--------------------------------------------------------------------------------
/Docs/Screenshots/InputDialog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/schdck/SimpleDialogs/d5bdc4ac9599e8b59ee739ce6fcf42f610b4e6e4/Docs/Screenshots/InputDialog.png
--------------------------------------------------------------------------------
/Docs/Screenshots/ProgressDialogs.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/schdck/SimpleDialogs/d5bdc4ac9599e8b59ee739ce6fcf42f610b4e6e4/Docs/Screenshots/ProgressDialogs.gif
--------------------------------------------------------------------------------
/Docs/Screenshots/SuccessDialog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/schdck/SimpleDialogs/d5bdc4ac9599e8b59ee739ce6fcf42f610b4e6e4/Docs/Screenshots/SuccessDialog.png
--------------------------------------------------------------------------------
/Docs/Screenshots/WarningDialog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/schdck/SimpleDialogs/d5bdc4ac9599e8b59ee739ce6fcf42f610b4e6e4/Docs/Screenshots/WarningDialog.png
--------------------------------------------------------------------------------
/Docs/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/schdck/SimpleDialogs/d5bdc4ac9599e8b59ee739ce6fcf42f610b4e6e4/Docs/logo.png
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Maurício Vielmo Schmaedeck
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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | [

](https://github.com/schdck/SimpleDialogs)
4 |
5 | # SimpleDialogs
6 |
7 | [](https://github.com/schdck/SimpleDialogs/blob/master/LICENSE)
8 | [](https://ci.appveyor.com/project/schdck/simpledialogs)
9 | [](https://www.nuget.org/packages/SimpleDialogs/)
10 | [](https://www.nuget.org/packages/SimpleDialogs/)
11 | [](https://github.com/schdck/SimpleDialogs/issues)
12 |
13 |
14 |
15 | :speech_balloon: SimpleDialogs is a simple framework to help displaying dialogs on a WPF app
16 |
17 |
18 |
19 |
20 | ## :bulb: About the project
21 | I made this project to make my life easier when displaying messages to the user, since it was something that I saw myself implementing over and over again. Also, I used it to practice a few new concepts that I was studying. It is far from perfect, but its something I'm proud of.
22 |
23 | Also: any help, tips, suggestions or critics are really appreciated.
24 |
25 | This project was heavily inspired/based on [Mahapps.Metro](https://github.com/MahApps/MahApps.Metro) (and its dialogs) and on [Mahapps.Metro.SimpleChildWindow](https://github.com/punker76/MahApps.Metro.SimpleChildWindow), so a special thanks to [@punker76](https://github.com/punker76) and all the other maintainers/contributors.
26 |
27 | ## :rocket: Getting started
28 |
29 | You can install SimpleDialogs through [NuGet](https://www.nuget.org/packages/SimpleDialogs/) by running the following command in the NuGet Package Manager Console
30 |
31 | ```bash
32 | PM> Install-Package SimpleDialogs
33 | ```
34 |
35 | ... or through NuGet Package Manager directly on your project/solution.
36 |
37 | Then just add one of the following `Resource Dictionary`
38 |
39 | ```XML
40 |
41 |
42 |
43 |
44 | ```
45 |
46 | ... to your application resources and you are good to go!
47 |
48 | **Also take a look at our :dart: [Quick start](https://github.com/schdck/SimpleDialogs/wiki/Quick-start) and at the :books: [Wiki](https://github.com/schdck/SimpleDialogs/wiki)**
49 |
50 | ## :camera: Screenshots
51 |
52 | #### Progress dialogs
53 |
56 |
57 | #### Information dialog
58 |
61 |
62 | #### Success dialog
63 |
66 |
67 | #### Warning dialog
68 |
71 |
72 | #### Error dialog
73 |
76 |
77 | #### Critical error dialog
78 |
81 |
82 | #### Input dialog
83 |
86 |
87 | #### Demo application
88 |
91 |
--------------------------------------------------------------------------------
/SimpleDialogs.Demo/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/SimpleDialogs.Demo/App.xaml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/SimpleDialogs.Demo/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 |
9 | namespace SimpleDialogs.Demo
10 | {
11 | ///
12 | /// Interaction logic for App.xaml
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/SimpleDialogs.Demo/FodyWeavers.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/SimpleDialogs.Demo/Helpers/MarginSetterHelper.cs:
--------------------------------------------------------------------------------
1 | using System.Windows;
2 | using System.Windows.Controls;
3 |
4 | namespace SimpleDialogs.Demo.Helpers
5 | {
6 | /* FROM: https://gist.github.com/angularsen/90040fb174f71c5ab3ad
7 | */
8 | public class MarginSetter
9 | {
10 | private static Thickness GetLastItemMargin(Panel obj)
11 | {
12 | return (Thickness)obj.GetValue(LastItemMarginProperty);
13 | }
14 |
15 | public static Thickness GetMargin(DependencyObject obj)
16 | {
17 | return (Thickness)obj.GetValue(MarginProperty);
18 | }
19 |
20 | private static void MarginChangedCallback(object sender, DependencyPropertyChangedEventArgs e)
21 | {
22 | // Make sure this is put on a panel
23 | var panel = sender as Panel;
24 | if (panel == null) return;
25 |
26 | // Avoid duplicate registrations
27 | panel.Loaded -= OnPanelLoaded;
28 | panel.Loaded += OnPanelLoaded;
29 |
30 | if (panel.IsLoaded)
31 | {
32 | OnPanelLoaded(panel, null);
33 | }
34 | }
35 |
36 | private static void OnPanelLoaded(object sender, RoutedEventArgs e)
37 | {
38 | var panel = (Panel)sender;
39 |
40 | // Go over the children and set margin for them:
41 | for (var i = 0; i < panel.Children.Count; i++)
42 | {
43 | UIElement child = panel.Children[i];
44 | var fe = child as FrameworkElement;
45 | if (fe == null) continue;
46 |
47 | bool isLastItem = i == panel.Children.Count - 1;
48 | fe.Margin = isLastItem ? GetLastItemMargin(panel) : GetMargin(panel);
49 | }
50 | }
51 |
52 | public static void SetLastItemMargin(DependencyObject obj, Thickness value)
53 | {
54 | obj.SetValue(LastItemMarginProperty, value);
55 | }
56 |
57 | public static void SetMargin(DependencyObject obj, Thickness value)
58 | {
59 | obj.SetValue(MarginProperty, value);
60 | }
61 |
62 | // Using a DependencyProperty as the backing store for Margin. This enables animation, styling, binding, etc...
63 | public static readonly DependencyProperty MarginProperty =
64 | DependencyProperty.RegisterAttached("Margin", typeof(Thickness), typeof(MarginSetter),
65 | new UIPropertyMetadata(new Thickness(), MarginChangedCallback));
66 |
67 | public static readonly DependencyProperty LastItemMarginProperty =
68 | DependencyProperty.RegisterAttached("LastItemMargin", typeof(Thickness), typeof(MarginSetter),
69 | new UIPropertyMetadata(new Thickness(), MarginChangedCallback));
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/SimpleDialogs.Demo/Helpers/SpacingHelper.cs:
--------------------------------------------------------------------------------
1 | using System.Windows;
2 |
3 | namespace SimpleDialogs.Demo.Helpers
4 | {
5 | public class Spacing
6 | {
7 | public static double GetHorizontal(DependencyObject obj)
8 | {
9 | return (double)obj.GetValue(HorizontalProperty);
10 | }
11 |
12 | public static double GetVertical(DependencyObject obj)
13 | {
14 | return (double)obj.GetValue(VerticalProperty);
15 | }
16 |
17 | private static void HorizontalChangedCallback(object sender, DependencyPropertyChangedEventArgs e)
18 | {
19 | var space = (double)e.NewValue;
20 | var obj = (DependencyObject)sender;
21 |
22 | MarginSetter.SetMargin(obj, new Thickness(0, 0, space, 0));
23 | MarginSetter.SetLastItemMargin(obj, new Thickness(0));
24 | }
25 |
26 | public static void SetHorizontal(DependencyObject obj, double space)
27 | {
28 | obj.SetValue(HorizontalProperty, space);
29 | }
30 |
31 | public static void SetVertical(DependencyObject obj, double value)
32 | {
33 | obj.SetValue(VerticalProperty, value);
34 | }
35 |
36 | private static void VerticalChangedCallback(object sender, DependencyPropertyChangedEventArgs e)
37 | {
38 | var space = (double)e.NewValue;
39 | var obj = (DependencyObject)sender;
40 | MarginSetter.SetMargin(obj, new Thickness(0, 0, 0, space));
41 | MarginSetter.SetLastItemMargin(obj, new Thickness(0));
42 | }
43 |
44 | public static readonly DependencyProperty VerticalProperty =
45 | DependencyProperty.RegisterAttached("Vertical", typeof(double), typeof(Spacing),
46 | new UIPropertyMetadata(0d, VerticalChangedCallback));
47 |
48 | public static readonly DependencyProperty HorizontalProperty =
49 | DependencyProperty.RegisterAttached("Horizontal", typeof(double), typeof(Spacing),
50 | new UIPropertyMetadata(0d, HorizontalChangedCallback));
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/SimpleDialogs.Demo/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
26 |
27 |
30 |
31 |
32 |
33 |
34 |
35 |
38 |
39 |
40 |
41 |
42 |
43 |
46 |
47 |
48 |
49 |
50 |
51 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
64 |
65 |
66 |
67 |
68 |
69 |
74 |
77 |
79 |
80 |
82 |
83 | Message dialog
84 | Progress dialog
85 | Input dialog
86 |
87 |
88 |
89 |
92 |
93 |
96 |
97 |
100 |
101 |
103 |
104 |
108 |
109 |
114 |
115 |
117 |
118 |
120 |
121 |
124 |
125 |
126 |
128 |
129 |
131 |
132 |
134 |
135 |
137 |
138 |
139 |
141 |
142 |
144 |
145 |
147 |
148 |
150 |
151 |
152 |
154 |
155 |
157 |
158 |
160 |
161 |
163 |
164 |
167 |
168 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
183 |
186 |
187 |
190 |
191 |
193 |
194 |
195 |
196 |
197 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
209 |
212 |
213 |
214 |
217 |
218 |
219 |
221 |
222 |
223 | github.com/schdck/SimpleDialogs
224 |
225 |
226 |
227 |
228 |
229 |
230 |
--------------------------------------------------------------------------------
/SimpleDialogs.Demo/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using MahApps.Metro.Controls;
2 | using System.Windows;
3 |
4 | namespace SimpleDialogs.Demo
5 | {
6 | ///
7 | /// Interaction logic for MainWindow.xaml
8 | ///
9 | public partial class MainWindow : MetroWindow
10 | {
11 | public static MainWindow Instance { get; private set; }
12 |
13 | public MainWindow()
14 | {
15 | Instance = this;
16 |
17 | InitializeComponent();
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/SimpleDialogs.Demo/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("SimpleDialogs.Demo")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("SimpleDialogs.Demo")]
15 | [assembly: AssemblyCopyright("Copyright © 2018")]
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 |
--------------------------------------------------------------------------------
/SimpleDialogs.Demo/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
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 SimpleDialogs.Demo.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", "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 | /// 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("SimpleDialogs.Demo.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 |
--------------------------------------------------------------------------------
/SimpleDialogs.Demo/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 |
--------------------------------------------------------------------------------
/SimpleDialogs.Demo/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
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 SimpleDialogs.Demo.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.3.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 |
--------------------------------------------------------------------------------
/SimpleDialogs.Demo/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/SimpleDialogs.Demo/Resources/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/schdck/SimpleDialogs/d5bdc4ac9599e8b59ee739ce6fcf42f610b4e6e4/SimpleDialogs.Demo/Resources/logo.png
--------------------------------------------------------------------------------
/SimpleDialogs.Demo/SimpleDialogs.Demo.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {5805D220-B339-4B14-9743-382D02EACE72}
8 | WinExe
9 | SimpleDialogs.Demo
10 | SimpleDialogs.Demo
11 | v4.5
12 | 512
13 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
14 | 4
15 | true
16 |
17 |
18 |
19 |
20 |
21 | AnyCPU
22 | true
23 | full
24 | false
25 | bin\Debug\
26 | DEBUG;TRACE
27 | prompt
28 | 4
29 |
30 |
31 | AnyCPU
32 | pdbonly
33 | true
34 | bin\Release\
35 | TRACE
36 | prompt
37 | 4
38 |
39 |
40 | icon.ico
41 |
42 |
43 | SimpleDialogs.Demo.App
44 |
45 |
46 |
47 | ..\packages\ControlzEx.3.0.2.4\lib\net45\ControlzEx.dll
48 |
49 |
50 | ..\packages\MvvmLightLibs.5.3.0.0\lib\net45\GalaSoft.MvvmLight.dll
51 |
52 |
53 | ..\packages\MvvmLightLibs.5.3.0.0\lib\net45\GalaSoft.MvvmLight.Extras.dll
54 |
55 |
56 | ..\packages\MvvmLightLibs.5.3.0.0\lib\net45\GalaSoft.MvvmLight.Platform.dll
57 |
58 |
59 | ..\packages\MahApps.Metro.1.6.5\lib\net45\MahApps.Metro.dll
60 |
61 |
62 | ..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll
63 |
64 |
65 | ..\packages\PropertyChanged.Fody.2.2.4.0\lib\netstandard1.0\PropertyChanged.dll
66 |
67 |
68 |
69 |
70 | ..\packages\ControlzEx.3.0.2.4\lib\net45\System.Windows.Interactivity.dll
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 | 4.0
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 | MSBuild:Compile
88 | Designer
89 |
90 |
91 |
92 |
93 |
94 |
95 | MSBuild:Compile
96 | Designer
97 |
98 |
99 | App.xaml
100 | Code
101 |
102 |
103 | MainWindow.xaml
104 | Code
105 |
106 |
107 |
108 |
109 | Code
110 |
111 |
112 | True
113 | True
114 | Resources.resx
115 |
116 |
117 | True
118 | Settings.settings
119 | True
120 |
121 |
122 | ResXFileCodeGenerator
123 | Resources.Designer.cs
124 |
125 |
126 |
127 | SettingsSingleFileGenerator
128 | Settings.Designer.cs
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 | {f06e9bca-4258-48c0-941d-465c243a595c}
137 | SimpleDialogs
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
154 |
155 |
156 |
157 |
--------------------------------------------------------------------------------
/SimpleDialogs.Demo/ViewModel/MainViewModel.cs:
--------------------------------------------------------------------------------
1 | using GalaSoft.MvvmLight;
2 | using GalaSoft.MvvmLight.Command;
3 | using SimpleDialogs.Controls;
4 | using SimpleDialogs.Enumerators;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Diagnostics;
8 | using System.Timers;
9 | using System.Windows;
10 | using System.Windows.Input;
11 |
12 | namespace SimpleDialogs.Demo.ViewModel
13 | {
14 | public class MainViewModel : ViewModelBase
15 | {
16 | public string DialogResult { get; private set; }
17 | public string DialogClickedButton { get; private set; }
18 |
19 | public bool IsFlyoutOpen { get; private set; } = true;
20 | public bool IsCreatingMessageDialog => SelectedType?.ToLower() == "message dialog";
21 | public bool IsCreatingProgressDialog => SelectedType?.ToLower() == "progress dialog";
22 | public bool IsCreatingInputDialog => SelectedType?.ToLower() == "input dialog";
23 |
24 | public string SelectedType { get; set; }
25 | public MessageSeverity? SelectedSeverity { get; set; }
26 | public DialogButton? SelectedButton { get; set; }
27 |
28 | public HorizontalAlignment? HorizontalAlignment { get; set; }
29 | public VerticalAlignment? VerticalAlignment { get; set; }
30 | public Thickness? Margin { get; set; }
31 |
32 | public int? SecondsToAutoClose { get; set; }
33 | public bool ShowOverlay { get; set; } = true;
34 | public bool CloseOnButtonClickByDefault { get; set; } = true;
35 | public bool IsUndefined { get; set; }
36 |
37 | public bool ShowFirstButton { get; set; } = true;
38 | public bool ShowSecondButton { get; set; }
39 | public bool ShowThirdButton { get; set; }
40 |
41 | public bool CloseOnFirstButton { get; set; } = true;
42 | public bool CloseOnSecondButton { get; set; } = true;
43 | public bool CloseOnThirdButton { get; set; } = true;
44 |
45 | public string FirstButtonContent { get; set; } = "OK";
46 | public string SecondButtonContent { get; set; }
47 | public string ThirdButtonContent { get; set; }
48 |
49 | public ICommand ShowFlyoutCommand { get; private set; }
50 | public ICommand ShowDialogCommand { get; private set; }
51 | public ICommand CloseCurrentDialogCommand { get; private set; }
52 | public ICommand OpenLinkCommand { get; private set; }
53 |
54 | private List DialogStack;
55 | private MessageDialog ErrorDialog;
56 |
57 | public MainViewModel()
58 | {
59 | DialogStack = new List();
60 |
61 | ErrorDialog = new MessageDialog()
62 | {
63 | Title = "ERROR",
64 | MessageSeverity = MessageSeverity.Error
65 | };
66 |
67 | ShowDialogCommand = new RelayCommand(() =>
68 | {
69 | ShowDialog();
70 |
71 | IsFlyoutOpen = false;
72 | });
73 |
74 | CloseCurrentDialogCommand = new RelayCommand(() =>
75 | {
76 | if(DialogStack.Count > 0)
77 | {
78 | var lastIndex = DialogStack.Count - 1;
79 | var lastDialog = DialogStack[lastIndex];
80 |
81 | DialogStack.RemoveAt(lastIndex);
82 | DialogManager.CloseDialogAsync(lastDialog);
83 | }
84 | });
85 |
86 | OpenLinkCommand = new RelayCommand((uri) =>
87 | {
88 | Process.Start(new ProcessStartInfo(uri.AbsoluteUri));
89 | });
90 |
91 | ShowFlyoutCommand = new RelayCommand(() =>
92 | {
93 | IsFlyoutOpen = true;
94 | });
95 | }
96 |
97 | private void ShowDialog()
98 | {
99 | if(SelectedType == null || SelectedButton == null)
100 | {
101 | ErrorDialog.Message = "Please inform the dialog type and auto focused button";
102 |
103 | DialogManager.ShowDialogAsync(this, ErrorDialog);
104 |
105 | return;
106 | }
107 |
108 | BaseDialog dialog = null;
109 |
110 | switch(SelectedType.ToLower())
111 | {
112 | case "message dialog":
113 | if(SelectedSeverity == null)
114 | {
115 | ErrorDialog.Message = "Please inform the message severity";
116 |
117 | DialogManager.ShowDialogAsync(this, ErrorDialog);
118 |
119 | return;
120 | }
121 |
122 | var messageDialog = new MessageDialog()
123 | {
124 | MessageSeverity = SelectedSeverity.Value,
125 | Title = "Message dialog"
126 | };
127 |
128 | switch(SelectedSeverity)
129 | {
130 | case MessageSeverity.Information:
131 | messageDialog.Message = "Move along.\n\nNothing to see here.";
132 | break;
133 |
134 | case MessageSeverity.Success:
135 | messageDialog.Message = "WE DID IT!!";
136 | messageDialog.FontSize = 14;
137 | break;
138 |
139 | case MessageSeverity.Warning:
140 | messageDialog.Message = "PLEASE BE CAREFUL (THIS IS A WARNING)";
141 | break;
142 |
143 | case MessageSeverity.Error:
144 | messageDialog.Message = "Some exception was caught.";
145 | messageDialog.Exception = new Exception("This is some exception that I got for you <3", new Exception("And this is its inner exception"));
146 | break;
147 |
148 | case MessageSeverity.Critical:
149 | messageDialog.Message = "Something really bad happend, so I'm gona leave a big message here:\n\nLorem ipsum dolor sit amet, vim melius doctus at. An modo movet vituperata eos, sit id doming noster. Quo quando putent et, mei in verterem adolescens. No dolore nemore referrentur pro, per mollis patrioque at. Saepe volumus petentium ei vel.\n\nLorem ipsum dolor sit amet, vim melius doctus at. An modo movet vituperata eos, sit id doming noster. Quo quando putent et, mei in verterem adolescens. No dolore nemore referrentur pro, per mollis patrioque at. Saepe volumus petentium ei vel.";
150 | break;
151 |
152 | }
153 |
154 | dialog = messageDialog;
155 |
156 | break;
157 |
158 | case "progress dialog":
159 | var progressDialog = new ProgressDialog()
160 | {
161 | IsUndefined = IsUndefined,
162 | Title = "PROGRESS DIALOG",
163 | Message = "Working...."
164 | };
165 |
166 | if(!IsUndefined)
167 | {
168 | var t = new Timer(50)
169 | {
170 | AutoReset = false
171 | };
172 |
173 | t.Elapsed += (s, e) =>
174 | {
175 | MainWindow.Instance.Dispatcher.Invoke(() =>
176 | {
177 | if (!progressDialog.IsClosed)
178 | {
179 | if (progressDialog.Progress < 100)
180 | {
181 | progressDialog.Progress++;
182 | progressDialog.Title = $"Working... ({progressDialog.Progress}%)";
183 | t.Start();
184 | }
185 | else
186 | {
187 | progressDialog.Title = "Done!";
188 | progressDialog.Message = "I don't know what I was doing, just know that it's finished.";
189 | }
190 | }
191 | });
192 | };
193 |
194 | t.Start();
195 | }
196 |
197 | dialog = progressDialog;
198 |
199 | break;
200 |
201 | case "input dialog":
202 | var inputDialog = new InputDialog()
203 | {
204 | Title = "INPUT DIALOG",
205 | Description = "Please insert any text you want",
206 | Watermark = "Insert your text here",
207 | };
208 |
209 | dialog = inputDialog;
210 |
211 | break;
212 | }
213 |
214 | if(dialog != null)
215 | {
216 | dialog.ShowOverlay = ShowOverlay;
217 | dialog.CloseOnButtonClickByDefault = CloseOnButtonClickByDefault;
218 | dialog.AutoFocusedButton = SelectedButton.Value;
219 |
220 | dialog.ShowFirstButton = ShowFirstButton;
221 | dialog.ShowSecondButton = ShowSecondButton;
222 | dialog.ShowThirdButton = ShowThirdButton;
223 |
224 | dialog.FirstButtonContent = FirstButtonContent;
225 | dialog.SecondButtonContent = SecondButtonContent;
226 | dialog.ThirdButtonContent = ThirdButtonContent;
227 |
228 | dialog.HorizontalAlignment = HorizontalAlignment ?? System.Windows.HorizontalAlignment.Center;
229 | dialog.VerticalAlignment = VerticalAlignment ?? System.Windows.VerticalAlignment.Center;
230 | dialog.Margin = Margin ?? new Thickness(5);
231 |
232 | dialog.Closed += DialogClosed;
233 | dialog.ButtonClicked += DialogButtonClicked;
234 |
235 | if(SecondsToAutoClose != null)
236 | {
237 | dialog.SecondsToAutoClose = SecondsToAutoClose.Value;
238 | }
239 |
240 | DialogStack.Add(dialog);
241 | DialogManager.ShowDialogAsync(this, dialog);
242 | }
243 | }
244 |
245 | private void DialogButtonClicked(object sender, DialogButtonClickedEventArgs e)
246 | {
247 | if (e.Button == DialogButton.FirstButton)
248 | {
249 | e.CloseDialogAfterHandle = CloseOnFirstButton;
250 | }
251 | else if (e.Button == DialogButton.SecondButton)
252 | {
253 | e.CloseDialogAfterHandle = CloseOnSecondButton;
254 | }
255 | else if (e.Button == DialogButton.ThirdButton)
256 | {
257 | e.CloseDialogAfterHandle = CloseOnThirdButton;
258 | }
259 | }
260 |
261 | private void DialogClosed(object sender, DialogClosedEventArgs e)
262 | {
263 | if (sender is BaseDialog dialog)
264 | {
265 | DialogStack.Remove(dialog);
266 | DialogResult = e.Result?.ToString();
267 |
268 | switch (e.ClickedButton)
269 | {
270 | case DialogButton.FirstButton:
271 | DialogClickedButton = $"FirstButton ({dialog.FirstButtonContent})";
272 | break;
273 |
274 | case DialogButton.SecondButton:
275 | DialogClickedButton = $"SecondButton ({dialog.SecondButtonContent})";
276 | break;
277 |
278 | case DialogButton.ThirdButton:
279 | DialogClickedButton = $"ThirdButton ({dialog.ThirdButtonContent})";
280 | break;
281 | }
282 | }
283 | }
284 | }
285 | }
--------------------------------------------------------------------------------
/SimpleDialogs.Demo/ViewModel/ViewModelLocator.cs:
--------------------------------------------------------------------------------
1 | /*
2 | In App.xaml:
3 |
4 |
6 |
7 |
8 | In the View:
9 | DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
10 |
11 | You can also use Blend to do all this with the tool's support.
12 | See http://www.galasoft.ch/mvvm
13 | */
14 |
15 | using GalaSoft.MvvmLight.Ioc;
16 | using Microsoft.Practices.ServiceLocation;
17 |
18 | namespace SimpleDialogs.Demo.ViewModel
19 | {
20 | ///
21 | /// This class contains static references to all the view models in the
22 | /// application and provides an entry point for the bindings.
23 | ///
24 | public class ViewModelLocator
25 | {
26 | ///
27 | /// Initializes a new instance of the ViewModelLocator class.
28 | ///
29 | public ViewModelLocator()
30 | {
31 | ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
32 |
33 | ////if (ViewModelBase.IsInDesignModeStatic)
34 | ////{
35 | //// // Create design time view services and models
36 | //// SimpleIoc.Default.Register();
37 | ////}
38 | ////else
39 | ////{
40 | //// // Create run time view services and models
41 | //// SimpleIoc.Default.Register();
42 | ////}
43 |
44 | SimpleIoc.Default.Register();
45 | }
46 |
47 | public MainViewModel Main
48 | {
49 | get
50 | {
51 | return ServiceLocator.Current.GetInstance();
52 | }
53 | }
54 |
55 | public static void Cleanup()
56 | {
57 | // TODO Clear the ViewModels
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/SimpleDialogs.Demo/icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/schdck/SimpleDialogs/d5bdc4ac9599e8b59ee739ce6fcf42f610b4e6e4/SimpleDialogs.Demo/icon.ico
--------------------------------------------------------------------------------
/SimpleDialogs.Demo/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/SimpleDialogs.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27004.2009
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleDialogs", "SimpleDialogs\SimpleDialogs.csproj", "{F06E9BCA-4258-48C0-941D-465C243A595C}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleDialogs.Demo", "SimpleDialogs.Demo\SimpleDialogs.Demo.csproj", "{5805D220-B339-4B14-9743-382D02EACE72}"
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 | {F06E9BCA-4258-48C0-941D-465C243A595C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {F06E9BCA-4258-48C0-941D-465C243A595C}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {F06E9BCA-4258-48C0-941D-465C243A595C}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {F06E9BCA-4258-48C0-941D-465C243A595C}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {5805D220-B339-4B14-9743-382D02EACE72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {5805D220-B339-4B14-9743-382D02EACE72}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {5805D220-B339-4B14-9743-382D02EACE72}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {5805D220-B339-4B14-9743-382D02EACE72}.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 = {0B82E12E-3CE9-4C95-8555-C86119EA916F}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/SimpleDialogs/Commands/SimpleCommand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Input;
3 |
4 | namespace SimpleDialogs.Commands
5 | {
6 | internal class SimpleCommand : ICommand
7 | {
8 | private Action action;
9 |
10 | #pragma warning disable 67
11 | public event EventHandler CanExecuteChanged;
12 | #pragma warning restore 67
13 |
14 | public SimpleCommand(Action action)
15 | {
16 | this.action = action;
17 | }
18 |
19 | public bool CanExecute(object parameter)
20 | {
21 | return true;
22 | }
23 |
24 | public void Execute(object parameter)
25 | {
26 | action?.Invoke();
27 | }
28 | }
29 |
30 | internal class SimpleCommand : ICommand
31 | {
32 | private Action action;
33 |
34 | #pragma warning disable 67
35 | public event EventHandler CanExecuteChanged;
36 | #pragma warning restore 67
37 |
38 | public SimpleCommand(Action action)
39 | {
40 | this.action = action;
41 | }
42 |
43 | public bool CanExecute(object parameter)
44 | {
45 | return true;
46 | }
47 |
48 | public void Execute(object parameter)
49 | {
50 | if(parameter is T param)
51 | {
52 | action?.Invoke(param);
53 | }
54 | else
55 | {
56 | throw new ArgumentException($"The parameter is not of type T ({ typeof(T) } )");
57 | }
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/SimpleDialogs/Controls/BaseDialog.cs:
--------------------------------------------------------------------------------
1 | using SimpleDialogs.Enumerators;
2 | using SimpleDialogs.Helpers;
3 | using System;
4 | using System.Threading.Tasks;
5 | using System.Timers;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Media;
9 |
10 | namespace SimpleDialogs.Controls
11 | {
12 | [TemplatePart(Name = "PART_FirstButton", Type = typeof(Button))]
13 | [TemplatePart(Name = "PART_SecondButton", Type = typeof(Button))]
14 | [TemplatePart(Name = "PART_ThirdButton", Type = typeof(Button))]
15 | public abstract class BaseDialog : ContentControl
16 | {
17 | private static readonly DependencyPropertyKey IsClosedPropertyKey = DependencyProperty.RegisterReadOnly(nameof(IsClosed), typeof(bool), typeof(BaseDialog), new PropertyMetadata(false));
18 |
19 | public static readonly DependencyProperty AlternativeForegroundProperty = DependencyProperty.Register(nameof(AlternativeForeground), typeof(Brush), typeof(BaseDialog));
20 |
21 | public static readonly DependencyProperty TitleFontSizeProperty = DependencyProperty.Register(nameof(TitleFontSize), typeof(double), typeof(BaseDialog));
22 | public static readonly DependencyProperty TitleFontWeightProperty = DependencyProperty.Register(nameof(TitleFontWeight), typeof(FontWeight), typeof(BaseDialog));
23 | public static readonly DependencyProperty TitleFontFamilyProperty = DependencyProperty.Register(nameof(TitleFontFamily), typeof(FontFamily), typeof(BaseDialog));
24 | public static readonly DependencyProperty TitleAlignmentProperty = DependencyProperty.Register(nameof(TitleAlignment), typeof(TextAlignment), typeof(BaseDialog));
25 | public static readonly DependencyProperty TitleForegroundProperty = DependencyProperty.Register(nameof(TitleForeground), typeof(Brush), typeof(BaseDialog));
26 | public static readonly DependencyProperty TitleProperty = DependencyProperty.Register(nameof(Title), typeof(string), typeof(BaseDialog));
27 |
28 | public static readonly DependencyProperty SecondsToAutoCloseProperty = DependencyProperty.Register(nameof(SecondsToAutoClose), typeof(int), typeof(BaseDialog), new PropertyMetadata(-1, DependencyPropertyChanged));
29 | public static readonly DependencyProperty ShowOverlayProperty = DependencyProperty.Register(nameof(ShowOverlay), typeof(bool), typeof(BaseDialog), new PropertyMetadata(true));
30 | public static readonly DependencyProperty IsClosedProperty = IsClosedPropertyKey.DependencyProperty;
31 | public static readonly DependencyProperty CloseOnButtonClickByDefaultProperty = DependencyProperty.Register(nameof(CloseOnButtonClickByDefault), typeof(bool), typeof(BaseDialog), new PropertyMetadata(true));
32 |
33 | public static readonly DependencyProperty DialogWidthProperty = DependencyProperty.Register(nameof(DialogWidth), typeof(double), typeof(BaseDialog), new PropertyMetadata(double.NaN));
34 | public static readonly DependencyProperty DialogHeightProperty = DependencyProperty.Register(nameof(DialogHeight), typeof(double), typeof(BaseDialog), new PropertyMetadata(double.NaN));
35 | public static readonly DependencyProperty TitleBarHeightProperty = DependencyProperty.Register(nameof(TitleBarHeight), typeof(double), typeof(BaseDialog));
36 |
37 | public static readonly DependencyProperty ShowFirstButtonProperty = DependencyProperty.Register(nameof(ShowFirstButton), typeof(bool), typeof(MessageDialog), new PropertyMetadata(true));
38 | public static readonly DependencyProperty ShowSecondButtonProperty = DependencyProperty.Register(nameof(ShowSecondButton), typeof(bool), typeof(MessageDialog), new PropertyMetadata(false));
39 | public static readonly DependencyProperty ShowThirdButtonProperty = DependencyProperty.Register(nameof(ShowThirdButton), typeof(bool), typeof(MessageDialog), new PropertyMetadata(false));
40 | public static readonly DependencyProperty FirstButtonContentProperty = DependencyProperty.Register(nameof(FirstButtonContent), typeof(string), typeof(MessageDialog), new PropertyMetadata("OK"));
41 | public static readonly DependencyProperty SecondButtonContentProperty = DependencyProperty.Register(nameof(SecondButtonContent), typeof(string), typeof(MessageDialog), new PropertyMetadata("CANCEL"));
42 | public static readonly DependencyProperty ThirdButtonContentProperty = DependencyProperty.Register(nameof(ThirdButtonContent), typeof(string), typeof(MessageDialog), new PropertyMetadata(null));
43 | public static readonly DependencyProperty AutoFocusedButtonProperty = DependencyProperty.Register(nameof(AutoFocusedButton), typeof(DialogButton), typeof(MessageDialog), new PropertyMetadata(DialogButton.None, DependencyPropertyChanged));
44 |
45 | private bool _InitializedButtons;
46 | private Timer _AutoCloseTimer;
47 | private Button _FirstButton;
48 | private Button _SecondButton;
49 | private Button _ThirdButton;
50 |
51 | internal DialogContainer Container { get; set; }
52 |
53 | public Brush AlternativeForeground
54 | {
55 | get => (Brush)GetValue(AlternativeForegroundProperty);
56 | set => SetValue(AlternativeForegroundProperty, value);
57 | }
58 |
59 | ///
60 | /// Gets or sets the title FontSize
61 | ///
62 | public double TitleFontSize
63 | {
64 | get => (double)GetValue(FontSizeProperty);
65 | set => SetValue(FontSizeProperty, value);
66 | }
67 |
68 | ///
69 | /// Gets or sets the title FontWeight
70 | ///
71 | public FontWeight TitleFontWeight
72 | {
73 | get => (FontWeight)GetValue(TitleFontWeightProperty);
74 | set => SetValue(TitleFontWeightProperty, value);
75 | }
76 |
77 | ///
78 | /// Gets or sets the title FontFamily
79 | ///
80 | public FontFamily TitleFontFamily
81 | {
82 | get => (FontFamily)GetValue(TitleFontFamilyProperty);
83 | set => SetValue(TitleFontFamilyProperty, value);
84 | }
85 |
86 | ///
87 | /// Gets or sets the title TextAlignment
88 | ///
89 | public TextAlignment TitleAlignment
90 | {
91 | get => (TextAlignment)GetValue(TitleAlignmentProperty);
92 | set => SetValue(TitleAlignmentProperty, value);
93 | }
94 |
95 | ///
96 | /// Gets or sets the title Foreground
97 | ///
98 | public Brush TitleForeground
99 | {
100 | get => (Brush)GetValue(TitleForegroundProperty);
101 | set => SetValue(TitleForegroundProperty, value);
102 | }
103 |
104 | ///
105 | /// Gets or sets the dialog title
106 | ///
107 | public string Title
108 | {
109 | get => (string)GetValue(TitleProperty);
110 | set => SetValue(TitleProperty, value);
111 | }
112 |
113 | ///
114 | /// Gets or sets the seconds remaining until the dialog auto closes
115 | ///
116 | ///
117 | /// The seconds until the dialog auto close or zero to disable auto close feature
118 | ///
119 | public int SecondsToAutoClose
120 | {
121 | get => (int)GetValue(SecondsToAutoCloseProperty);
122 | set => SetValue(SecondsToAutoCloseProperty, value);
123 | }
124 |
125 | ///
126 | /// Gets or sets a value indicating whether the dialog should be shown with an overlay
127 | ///
128 | public bool ShowOverlay
129 | {
130 | get => (bool)GetValue(ShowOverlayProperty);
131 | set => SetValue(ShowOverlayProperty, value);
132 | }
133 |
134 | ///
135 | /// Gets a value indicating if the dialog has been closed
136 | ///
137 | public bool IsClosed
138 | {
139 | get => (bool)GetValue(IsClosedProperty);
140 | private set => SetValue(IsClosedPropertyKey, value);
141 | }
142 |
143 | ///
144 | /// Gets or sets a value indicating if the dialog should be closed when a button is clicked
145 | ///
146 | public bool CloseOnButtonClickByDefault
147 | {
148 | get => (bool)GetValue(CloseOnButtonClickByDefaultProperty);
149 | set => SetValue(CloseOnButtonClickByDefaultProperty, value);
150 | }
151 |
152 | ///
153 | /// Gets or sets the dialog width
154 | ///
155 | public double DialogWidth
156 | {
157 | get => (double)GetValue(DialogWidthProperty);
158 | set => SetValue(DialogWidthProperty, value);
159 | }
160 |
161 | ///
162 | /// Gets or sets the dialog height
163 | ///
164 | public double DialogHeight
165 | {
166 | get => (double)GetValue(DialogHeightProperty);
167 | set => SetValue(DialogHeightProperty, value);
168 | }
169 |
170 | ///
171 | /// Gets or sets the title bar height
172 | ///
173 | public double TitleBarHeight
174 | {
175 | get => (double)GetValue(TitleBarHeightProperty);
176 | set => SetValue(TitleBarHeightProperty, value);
177 | }
178 |
179 | ///
180 | /// Gets or sets a value indicating whether to show the first button of the dialog
181 | ///
182 | public bool ShowFirstButton
183 | {
184 | get => (bool)GetValue(ShowFirstButtonProperty);
185 | set => SetValue(ShowFirstButtonProperty, value);
186 | }
187 |
188 | ///
189 | /// Gets or sets a value indicating whether to show the second button of the dialog
190 | ///
191 | public bool ShowSecondButton
192 | {
193 | get => (bool)GetValue(ShowSecondButtonProperty);
194 | set => SetValue(ShowSecondButtonProperty, value);
195 | }
196 |
197 | ///
198 | /// Gets or sets a value indicating whether to show the third button of the dialog
199 | ///
200 | public bool ShowThirdButton
201 | {
202 | get => (bool)GetValue(ShowThirdButtonProperty);
203 | set => SetValue(ShowThirdButtonProperty, value);
204 | }
205 |
206 | ///
207 | /// Gets or sets the first button content
208 | ///
209 | public string FirstButtonContent
210 | {
211 | get => (string)GetValue(FirstButtonContentProperty);
212 | set => SetValue(FirstButtonContentProperty, value);
213 | }
214 |
215 | ///
216 | /// Gets or sets the second button content
217 | ///
218 | public string SecondButtonContent
219 | {
220 | get => (string)GetValue(SecondButtonContentProperty);
221 | set => SetValue(SecondButtonContentProperty, value);
222 | }
223 |
224 | ///
225 | /// Gets or sets the content of the third dialog button
226 | ///
227 | public string ThirdButtonContent
228 | {
229 | get => (string)GetValue(ThirdButtonContentProperty);
230 | set => SetValue(ThirdButtonContentProperty, value);
231 | }
232 |
233 | ///
234 | /// Gets or sets the button that should be automatically focused when the dialog is open
235 | ///
236 | public DialogButton AutoFocusedButton
237 | {
238 | get => (DialogButton)GetValue(AutoFocusedButtonProperty);
239 | set => SetValue(AutoFocusedButtonProperty, value);
240 | }
241 |
242 | public event EventHandler ButtonClicked;
243 | public event EventHandler Closed;
244 |
245 | public BaseDialog()
246 | {
247 | _AutoCloseTimer = new Timer(1000)
248 | {
249 | AutoReset = false
250 | };
251 |
252 | _AutoCloseTimer.Elapsed += (s, e) => Dispatcher.Invoke(() =>
253 | {
254 | SecondsToAutoClose--;
255 | });
256 |
257 | Loaded += HandleLoadedEvent;
258 | }
259 |
260 | protected virtual object GetResult()
261 | {
262 | return null;
263 | }
264 |
265 | protected void CloseDialog(DialogButton clickedButton)
266 | {
267 | SecondsToAutoClose = -1;
268 | IsClosed = true;
269 |
270 | Closed?.Invoke(this, new DialogClosedEventArgs(clickedButton, GetResult()));
271 | }
272 |
273 | internal Task WaitForLoadAsync()
274 | {
275 | var taskCompletionSource = new TaskCompletionSource