Skip to content

Commit 688efd0

Browse files
Working on issues #1 and #2
1 parent b186326 commit 688efd0

18 files changed

+625
-29
lines changed

MessageDialogManagerLib.sln

+19-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 16
44
VisualStudioVersion = 16.0.29613.14
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MessageDialogManagerLib", "MessageDialogManagerLib\MessageDialogManagerLib.csproj", "{AFF53905-D1F8-49A2-B75C-584E73FC7C24}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MessageDialogManagerLib", "MessageDialogManagerLib\MessageDialogManagerLib.csproj", "{AFF53905-D1F8-49A2-B75C-584E73FC7C24}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{0433A1E6-C112-44A9-A04B-D28A5152CE7A}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommandLibrary", "Samples\CommandLibrary\CommandLibrary.csproj", "{F50AA0D6-29A6-484D-8FE0-A0A4D054143A}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetFrameworkSample", "Samples\NetFrameworkSample\NetFrameworkSample.csproj", "{DDBACA7F-556E-4D69-8E3F-CB3FBE58A2D4}"
713
EndProject
814
Global
915
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -15,10 +21,22 @@ Global
1521
{AFF53905-D1F8-49A2-B75C-584E73FC7C24}.Debug|Any CPU.Build.0 = Debug|Any CPU
1622
{AFF53905-D1F8-49A2-B75C-584E73FC7C24}.Release|Any CPU.ActiveCfg = Release|Any CPU
1723
{AFF53905-D1F8-49A2-B75C-584E73FC7C24}.Release|Any CPU.Build.0 = Release|Any CPU
24+
{F50AA0D6-29A6-484D-8FE0-A0A4D054143A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25+
{F50AA0D6-29A6-484D-8FE0-A0A4D054143A}.Debug|Any CPU.Build.0 = Debug|Any CPU
26+
{F50AA0D6-29A6-484D-8FE0-A0A4D054143A}.Release|Any CPU.ActiveCfg = Release|Any CPU
27+
{F50AA0D6-29A6-484D-8FE0-A0A4D054143A}.Release|Any CPU.Build.0 = Release|Any CPU
28+
{DDBACA7F-556E-4D69-8E3F-CB3FBE58A2D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{DDBACA7F-556E-4D69-8E3F-CB3FBE58A2D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{DDBACA7F-556E-4D69-8E3F-CB3FBE58A2D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{DDBACA7F-556E-4D69-8E3F-CB3FBE58A2D4}.Release|Any CPU.Build.0 = Release|Any CPU
1832
EndGlobalSection
1933
GlobalSection(SolutionProperties) = preSolution
2034
HideSolutionNode = FALSE
2135
EndGlobalSection
36+
GlobalSection(NestedProjects) = preSolution
37+
{F50AA0D6-29A6-484D-8FE0-A0A4D054143A} = {0433A1E6-C112-44A9-A04B-D28A5152CE7A}
38+
{DDBACA7F-556E-4D69-8E3F-CB3FBE58A2D4} = {0433A1E6-C112-44A9-A04B-D28A5152CE7A}
39+
EndGlobalSection
2240
GlobalSection(ExtensibilityGlobals) = postSolution
2341
SolutionGuid = {294B7020-3632-48C2-BF40-DFF00FE15C57}
2442
EndGlobalSection

MessageDialogManagerLib/Command.cs

+2-7
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,15 @@
33

44
namespace MessageDialogManagerLib
55
{
6-
public class Command : ICommand
6+
class Command : ICommand
77
{
88
private readonly Action _execute;
99

1010
private readonly Func<bool> _canExecute;
1111

1212
public Command(Action execute, Func<bool> canExecute)
1313
{
14-
if (execute == null)
15-
{
16-
throw new ArgumentNullException("execute");
17-
}
18-
19-
_execute = execute;
14+
_execute = execute ?? throw new ArgumentNullException("execute");
2015

2116
if (canExecute != null)
2217
{

MessageDialogManagerLib/MessageDialogManagerLib.csproj

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
22

33
<PropertyGroup>
4-
<TargetFramework>net472</TargetFramework>
4+
<TargetFrameworks>net452;net46;net47;netcoreapp3.0;netcoreapp3.1</TargetFrameworks>
55
<Authors>Evaristo Cuesta</Authors>
66
<Company>Evaristo Cuesta</Company>
77
<Description>Library to easily use dialogs from a View Model in a Mahapps Metro App.</Description>
@@ -15,11 +15,16 @@
1515
<Copyright>Copyright © 2020 Evaristo Cuesta</Copyright>
1616
<iconUrl>https://raw.githubusercontent.com/evaristocuesta/MessageDialogManagerLib/master/logo.png</iconUrl>
1717
<PackageIcon>logo.png</PackageIcon>
18+
<UseWpf>true</UseWpf>
19+
<UseWindowsForms>true</UseWindowsForms>
20+
<AssemblyVersion>1.0.1.0</AssemblyVersion>
21+
<FileVersion>1.0.1.0</FileVersion>
22+
<Version>1.0.1</Version>
1823
</PropertyGroup>
1924

2025
<ItemGroup>
26+
<PackageReference Include="FolderBrowserEx" Version="1.0.0" />
2127
<PackageReference Include="MahApps.Metro" Version="2.2.0" />
22-
<PackageReference Include="WPFFolderBrowser" Version="1.0.2" />
2328
</ItemGroup>
2429

2530
<ItemGroup>

MessageDialogManagerLib/MessageDialogManagerMahapps.cs

+12-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
using MahApps.Metro.Controls;
1+
using FolderBrowserEx;
2+
using MahApps.Metro.Controls;
23
using MahApps.Metro.Controls.Dialogs;
34
using Microsoft.Win32;
45
using System.Collections.Generic;
56
using System.IO;
67
using System.Threading.Tasks;
7-
using System.Web.UI.WebControls;
88
using System.Windows;
9-
using System.Windows.Input;
10-
using WPFFolderBrowser;
9+
using System.Windows.Forms;
10+
using FolderBrowserDialog = FolderBrowserEx.FolderBrowserDialog;
1111

1212
namespace MessageDialogManagerLib
1313
{
1414
public class MessageDialogManagerMahapps : IMessageDialogManager
1515
{
1616
private ProgressDialogController _controller;
17-
private Application _app;
17+
private System.Windows.Application _app;
1818
/// <summary>
1919
/// We have to use this private variable instead a local variable to show a custom dialog
2020
/// to avoid an error closing the dialog
@@ -26,7 +26,7 @@ public class MessageDialogManagerMahapps : IMessageDialogManager
2626
public string FolderPath { get; set; }
2727
public string FilePath { get; set; }
2828

29-
public MessageDialogManagerMahapps(Application app)
29+
public MessageDialogManagerMahapps(System.Windows.Application app)
3030
{
3131
_app = app;
3232
_customDialogs = new Dictionary<IDialogViewModel, CustomDialog>();
@@ -77,18 +77,12 @@ public async Task CloseProgress()
7777
public bool ShowFolderBrowser(string title, string initialDirectory)
7878
{
7979
bool res = false;
80-
WPFFolderBrowserDialog ofd = new WPFFolderBrowserDialog();
81-
82-
if (Directory.Exists(initialDirectory))
83-
ofd.InitialDirectory = initialDirectory;
84-
else
85-
ofd.InitialDirectory = "";
86-
ofd.Title = title;
87-
88-
if (ofd.ShowDialog() == true)
80+
FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
81+
folderBrowserDialog.Title = title;
82+
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
8983
{
90-
FolderPath = ofd.FileName;
91-
res = true;
84+
FolderPath = folderBrowserDialog.SelectedFolder;
85+
res = true;
9286
}
9387
return res;
9488
}
@@ -97,7 +91,7 @@ public bool ShowFileBrowser(string title, string initialPath, string filter)
9791
{
9892
bool res = false;
9993

100-
OpenFileDialog openFileDialog = new OpenFileDialog();
94+
Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();
10195
if (Directory.Exists(initialPath))
10296
openFileDialog.InitialDirectory = initialPath;
10397
else

Samples/CommandLibrary/Command.cs

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Windows.Input;
3+
4+
namespace CommandLibrary
5+
{
6+
public class Command : ICommand
7+
{
8+
private readonly Action _execute;
9+
10+
private readonly Func<bool> _canExecute;
11+
12+
public Command(Action execute, Func<bool> canExecute)
13+
{
14+
if (execute == null)
15+
{
16+
throw new ArgumentNullException("execute");
17+
}
18+
19+
_execute = execute;
20+
21+
if (canExecute != null)
22+
{
23+
_canExecute = canExecute;
24+
}
25+
}
26+
27+
#region ICommand Members
28+
29+
public bool CanExecute(object parameter)
30+
{
31+
return _canExecute == null || _canExecute.Invoke();
32+
}
33+
public event EventHandler CanExecuteChanged
34+
{
35+
add { CommandManager.RequerySuggested += value; }
36+
remove { CommandManager.RequerySuggested -= value; }
37+
}
38+
39+
public void Execute(object parameter)
40+
{
41+
if (CanExecute(parameter) && _execute != null)
42+
{
43+
_execute.Invoke();
44+
}
45+
}
46+
#endregion
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net452;net46;net47</TargetFrameworks>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<Reference Include="PresentationCore" />
9+
<Reference Include="PresentationFramework" />
10+
</ItemGroup>
11+
12+
</Project>

Samples/NetFrameworkSample/App.config

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>

Samples/NetFrameworkSample/App.xaml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Application x:Class="NetFrameworkSample.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:NetFrameworkSample"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
10+
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
11+
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Dark.Blue.xaml" />
12+
</ResourceDictionary.MergedDictionaries>
13+
</ResourceDictionary>
14+
</Application.Resources>
15+
</Application>
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 NetFrameworkSample
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<mahapps:MetroWindow x:Class="NetFrameworkSample.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:NetFrameworkSample"
7+
xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls"
8+
mc:Ignorable="d"
9+
Title="MainWindow" Height="450" Width="800">
10+
<Grid>
11+
<Grid.ColumnDefinitions>
12+
<ColumnDefinition Width="*" />
13+
<ColumnDefinition Width="*" />
14+
<ColumnDefinition Width="*" />
15+
</Grid.ColumnDefinitions>
16+
<Grid.RowDefinitions>
17+
<RowDefinition Height="*" />
18+
<RowDefinition Height="*" />
19+
<RowDefinition Height="*" />
20+
</Grid.RowDefinitions>
21+
<Button Content="Folder Browser"
22+
Command="{Binding ShowFolderBrowserCommand}" />
23+
<Button Content="File Browser"
24+
Grid.Column="1"
25+
Command="{Binding ShowFileBrowserCommand}" />
26+
</Grid>
27+
</mahapps:MetroWindow>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using MahApps.Metro.Controls;
2+
using MessageDialogManagerLib;
3+
4+
namespace NetFrameworkSample
5+
{
6+
/// <summary>
7+
/// Interaction logic for MainWindow.xaml
8+
/// </summary>
9+
public partial class MainWindow : MetroWindow
10+
{
11+
public MainWindow()
12+
{
13+
InitializeComponent();
14+
DataContext = new MainWindowViewModel(new MessageDialogManagerMahapps(App.Current));
15+
}
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using CommandLibrary;
2+
using MessageDialogManagerLib;
3+
using System.Windows.Input;
4+
5+
namespace NetFrameworkSample
6+
{
7+
public class MainWindowViewModel
8+
{
9+
private IMessageDialogManager _messageDialogManager;
10+
11+
public MainWindowViewModel(IMessageDialogManager messageDialogManager)
12+
{
13+
_messageDialogManager = messageDialogManager;
14+
ShowFolderBrowserCommand = new Command(ShowFolderBrowserCommandExecute, ShowFolderBrowserCommandCanExecute);
15+
ShowFileBrowserCommand = new Command(ShowFileBrowserCommandExecute, ShowFileBrowserCommandCanExecute);
16+
}
17+
18+
public ICommand ShowFolderBrowserCommand { get; private set; }
19+
20+
public ICommand ShowFileBrowserCommand { get; private set; }
21+
22+
private bool ShowFolderBrowserCommandCanExecute()
23+
{
24+
return true;
25+
}
26+
27+
private void ShowFolderBrowserCommandExecute()
28+
{
29+
if (_messageDialogManager.ShowFolderBrowser("Select a folder", ""))
30+
_messageDialogManager.ShowInfoDialogAsync("Folder Selected", _messageDialogManager.FolderPath);
31+
}
32+
33+
private bool ShowFileBrowserCommandCanExecute()
34+
{
35+
return true;
36+
}
37+
38+
private void ShowFileBrowserCommandExecute()
39+
{
40+
if (_messageDialogManager.ShowFileBrowser("Select a file", "", "*.* | *.*"))
41+
_messageDialogManager.ShowInfoDialogAsync("File Selected", _messageDialogManager.FilePath);
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)