├── .gitattributes ├── .gitignore ├── FriendEditor.sln ├── FriendEditor ├── App.config ├── App.xaml ├── App.xaml.cs ├── Assets │ ├── Code.png │ └── User.png ├── Controls │ ├── FriendControl.xaml │ └── FriendControl.xaml.cs ├── Converters │ ├── BooleanToVisibilityConverter.cs │ └── NullToVisibilityConverter.cs ├── EventArgs │ ├── CloseWindowEventArgs.cs │ └── OpenEditWindowArgs.cs ├── FriendEditor.csproj ├── Models │ ├── Friend.cs │ └── IFriend.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Services │ ├── DialogService.cs │ ├── EditWindowController.cs │ ├── IDataProvider.cs │ ├── IDialogService.cs │ ├── IEditWindowController.cs │ └── SqliteDataProvider.cs ├── ViewModels │ ├── EditViewModel.cs │ ├── MainViewModel.cs │ └── ViewModelLocator.cs ├── Views │ ├── EditWindow.xaml │ ├── EditWindow.xaml.cs │ ├── MainWindow.xaml │ └── MainWindow.xaml.cs └── packages.config ├── README.md └── Screenshots ├── Edit.png └── Main.png /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc -------------------------------------------------------------------------------- /FriendEditor.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26228.9 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FriendEditor", "FriendEditor\FriendEditor.csproj", "{D5F4F53B-544D-4727-8580-DED448127DD3}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{71FCF6E1-C886-4E1E-96FC-183B3B369D5D}" 9 | ProjectSection(SolutionItems) = preProject 10 | README.md = README.md 11 | EndProjectSection 12 | EndProject 13 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Screenshots", "Screenshots", "{6AF7AD22-CEA2-4921-93C0-DA78887FCF27}" 14 | ProjectSection(SolutionItems) = preProject 15 | Screenshots\Edit.png = Screenshots\Edit.png 16 | Screenshots\Main.png = Screenshots\Main.png 17 | EndProjectSection 18 | EndProject 19 | Global 20 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 21 | Debug|Any CPU = Debug|Any CPU 22 | Release|Any CPU = Release|Any CPU 23 | EndGlobalSection 24 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 25 | {D5F4F53B-544D-4727-8580-DED448127DD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 26 | {D5F4F53B-544D-4727-8580-DED448127DD3}.Debug|Any CPU.Build.0 = Debug|Any CPU 27 | {D5F4F53B-544D-4727-8580-DED448127DD3}.Release|Any CPU.ActiveCfg = Release|Any CPU 28 | {D5F4F53B-544D-4727-8580-DED448127DD3}.Release|Any CPU.Build.0 = Release|Any CPU 29 | EndGlobalSection 30 | GlobalSection(SolutionProperties) = preSolution 31 | HideSolutionNode = FALSE 32 | EndGlobalSection 33 | GlobalSection(NestedProjects) = preSolution 34 | {6AF7AD22-CEA2-4921-93C0-DA78887FCF27} = {71FCF6E1-C886-4E1E-96FC-183B3B369D5D} 35 | EndGlobalSection 36 | EndGlobal 37 | -------------------------------------------------------------------------------- /FriendEditor/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /FriendEditor/App.xaml: -------------------------------------------------------------------------------- 1 |  7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /FriendEditor/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using FriendEditor.Services; 2 | using FriendEditor.Views; 3 | using GalaSoft.MvvmLight.Ioc; 4 | using System.Windows; 5 | 6 | namespace FriendEditor 7 | { 8 | /// 9 | /// Interaction logic for App.xaml 10 | /// 11 | public partial class App : Application 12 | { 13 | private void Application_Startup(object sender, StartupEventArgs e) 14 | { 15 | SimpleIoc.Default.Register(); 16 | SimpleIoc.Default.Register(); 17 | SimpleIoc.Default.Register(); 18 | 19 | App.Current.DispatcherUnhandledException += (s, args) => 20 | { 21 | SimpleIoc.Default.GetInstance().Exception(args.Exception); 22 | args.Handled = true; 23 | }; 24 | 25 | MainWindow mainWindow = new MainWindow(); 26 | App.Current.MainWindow = mainWindow; 27 | mainWindow.Show(); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /FriendEditor/Assets/Code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imnbwd/FriendEditor/6047727885ed0a00e0b3251e2c9af8e81f6b8e87/FriendEditor/Assets/Code.png -------------------------------------------------------------------------------- /FriendEditor/Assets/User.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imnbwd/FriendEditor/6047727885ed0a00e0b3251e2c9af8e81f6b8e87/FriendEditor/Assets/User.png -------------------------------------------------------------------------------- /FriendEditor/Controls/FriendControl.xaml: -------------------------------------------------------------------------------- 1 |  11 | 12 | 0,10,0,0 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 29 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /FriendEditor/Controls/FriendControl.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Controls; 2 | 3 | namespace FriendEditor.Controls 4 | { 5 | /// 6 | /// Interaction logic for FriendControl.xaml 7 | /// 8 | public partial class FriendControl : UserControl 9 | { 10 | public FriendControl() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /FriendEditor/Converters/BooleanToVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | 6 | namespace FriendEditor.Converters 7 | { 8 | public class BooleanToVisibilityConverter : IValueConverter 9 | { 10 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 11 | { 12 | return (value != null && (bool)value) ? Visibility.Visible : Visibility.Collapsed; 13 | } 14 | 15 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 16 | { 17 | throw new NotImplementedException(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /FriendEditor/Converters/NullToVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | 6 | namespace FriendEditor.Converters 7 | { 8 | public class NullToVisibilityConverter : IValueConverter 9 | { 10 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 11 | { 12 | return value != null ? Visibility.Visible : Visibility.Collapsed; 13 | } 14 | 15 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 16 | { 17 | throw new NotImplementedException(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /FriendEditor/EventArgs/CloseWindowEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace FriendEditor.EventArgs 2 | { 3 | public class CloseWindowEventArgs 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /FriendEditor/EventArgs/OpenEditWindowArgs.cs: -------------------------------------------------------------------------------- 1 | using FriendEditor.Models; 2 | 3 | namespace FriendEditor.EventArgs 4 | { 5 | /// 6 | /// Action Type 7 | /// 8 | public enum ActionType 9 | { 10 | /// 11 | /// Add a friend 12 | /// 13 | Add, 14 | 15 | /// 16 | /// Edit a friend 17 | /// 18 | Edit 19 | } 20 | 21 | /// 22 | /// Open EditWindow arguments 23 | /// 24 | public class OpenEditWindowArgs 25 | { 26 | /// 27 | /// If is Edit, then the value for this property need to be provided 28 | /// 29 | public Friend Friend { get; set; } 30 | 31 | public ActionType Type { get; set; } 32 | } 33 | } -------------------------------------------------------------------------------- /FriendEditor/FriendEditor.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {D5F4F53B-544D-4727-8580-DED448127DD3} 8 | WinExe 9 | FriendEditor 10 | FriendEditor 11 | v4.5.2 12 | 512 13 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 4 15 | true 16 | 17 | 18 | 19 | 20 | AnyCPU 21 | true 22 | full 23 | false 24 | bin\Debug\ 25 | DEBUG;TRACE 26 | prompt 27 | 4 28 | 29 | 30 | AnyCPU 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | 38 | 39 | 40 | ..\packages\MvvmLightLibs.5.3.0.0\lib\net45\GalaSoft.MvvmLight.dll 41 | 42 | 43 | ..\packages\MvvmLightLibs.5.3.0.0\lib\net45\GalaSoft.MvvmLight.Extras.dll 44 | 45 | 46 | ..\packages\MvvmLightLibs.5.3.0.0\lib\net45\GalaSoft.MvvmLight.Platform.dll 47 | 48 | 49 | 50 | ..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll 51 | 52 | 53 | 54 | 55 | ..\packages\System.Data.SQLite.Core.1.0.104.0\lib\net451\System.Data.SQLite.dll 56 | 57 | 58 | ..\packages\MvvmLightLibs.5.3.0.0\lib\net45\System.Windows.Interactivity.dll 59 | True 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 4.0 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | MSBuild:Compile 77 | Designer 78 | 79 | 80 | App.xaml 81 | Code 82 | 83 | 84 | FriendControl.xaml 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | EditWindow.xaml 103 | 104 | 105 | MainWindow.xaml 106 | 107 | 108 | 109 | 110 | Code 111 | 112 | 113 | True 114 | True 115 | Resources.resx 116 | 117 | 118 | True 119 | Settings.settings 120 | True 121 | 122 | 123 | ResXFileCodeGenerator 124 | Resources.Designer.cs 125 | 126 | 127 | 128 | SettingsSingleFileGenerator 129 | Settings.Designer.cs 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | Designer 138 | MSBuild:Compile 139 | 140 | 141 | Designer 142 | MSBuild:Compile 143 | 144 | 145 | Designer 146 | MSBuild:Compile 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 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}. 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /FriendEditor/Models/Friend.cs: -------------------------------------------------------------------------------- 1 | using GalaSoft.MvvmLight; 2 | using System; 3 | 4 | namespace FriendEditor.Models 5 | { 6 | public class Friend : ObservableObject, IFriend 7 | { 8 | private DateTime _birthDate; 9 | private string _email; 10 | private string _id; 11 | private bool _isDeveloper; 12 | private string _name; 13 | 14 | /// 15 | /// Get or set BirthDate value 16 | /// 17 | public DateTime BirthDate 18 | { 19 | get { return _birthDate; } 20 | set { Set(ref _birthDate, value); } 21 | } 22 | 23 | /// 24 | /// Get or set Email value 25 | /// 26 | public string Email 27 | { 28 | get { return _email; } 29 | set { Set(ref _email, value); } 30 | } 31 | 32 | /// 33 | /// Get or set Id value 34 | /// 35 | public string Id 36 | { 37 | get { return _id; } 38 | set { Set(ref _id, value); } 39 | } 40 | 41 | /// 42 | /// Get or set IsDeveloper value 43 | /// 44 | public bool IsDeveloper 45 | { 46 | get { return _isDeveloper; } 47 | set { Set(ref _isDeveloper, value); } 48 | } 49 | 50 | /// 51 | /// Get or set Name value 52 | /// 53 | public string Name 54 | { 55 | get { return _name; } 56 | set { Set(ref _name, value); } 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /FriendEditor/Models/IFriend.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace FriendEditor.Models 4 | { 5 | public interface IFriend 6 | { 7 | DateTime BirthDate { get; set; } 8 | string Email { get; set; } 9 | string Id { get; set; } 10 | bool IsDeveloper { get; set; } 11 | 12 | string Name { get; set; } 13 | } 14 | } -------------------------------------------------------------------------------- /FriendEditor/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | using System.Windows; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("FriendEditor")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("FriendEditor")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | //In order to begin building localizable applications, set 23 | //CultureYouAreCodingWith in your .csproj file 24 | //inside a . For example, if you are using US english 25 | //in your source files, set the to en-US. Then uncomment 26 | //the NeutralResourceLanguage attribute below. Update the "en-US" in 27 | //the line below to match the UICulture setting in the project file. 28 | 29 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 30 | 31 | [assembly: ThemeInfo( 32 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 33 | //(used if a resource is not found in the page, 34 | // or application resource dictionaries) 35 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 36 | //(used if a resource is not found in the page, 37 | // app, or any theme specific resource dictionaries) 38 | )] 39 | 40 | // Version information for an assembly consists of the following four values: 41 | // 42 | // Major Version 43 | // Minor Version 44 | // Build Number 45 | // Revision 46 | // 47 | // You can specify all the values or you can default the Build and Revision Numbers 48 | // by using the '*' as shown below: 49 | // [assembly: AssemblyVersion("1.0.*")] 50 | [assembly: AssemblyVersion("1.0.0.0")] 51 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /FriendEditor/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 FriendEditor.Properties 12 | { 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 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// Returns the cached ResourceManager instance used by this class. 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("FriendEditor.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// Overrides the current thread's CurrentUICulture property for all 56 | /// resource lookups using this strongly typed resource class. 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /FriendEditor/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 | -------------------------------------------------------------------------------- /FriendEditor/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 FriendEditor.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /FriendEditor/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /FriendEditor/Services/DialogService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | 4 | namespace FriendEditor.Services 5 | { 6 | public class DialogService : IDialogService 7 | { 8 | public bool Confirm(string message) 9 | { 10 | var result = MessageBox.Show(message, "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Question); 11 | return result == MessageBoxResult.Yes ? true : false; 12 | } 13 | 14 | public void Exception(Exception ex) 15 | { 16 | string message = $@"An exception thrown: {ex.Message} 17 | 18 | {ex.ToString()}"; 19 | MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); 20 | } 21 | 22 | public void ShowMessage(string message) 23 | { 24 | MessageBox.Show(message, "Info", MessageBoxButton.OK, MessageBoxImage.Information); 25 | } 26 | 27 | public void Warning(string message) 28 | { 29 | MessageBox.Show(message, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /FriendEditor/Services/EditWindowController.cs: -------------------------------------------------------------------------------- 1 | using FriendEditor.EventArgs; 2 | using FriendEditor.Views; 3 | using GalaSoft.MvvmLight.Ioc; 4 | 5 | namespace FriendEditor.Services 6 | { 7 | public class EditWindowController : IEditWindowController 8 | { 9 | /// 10 | /// Show EditWindow 11 | /// 12 | /// 13 | /// 14 | public bool? ShowDialog(OpenEditWindowArgs args) 15 | { 16 | // If the container contains then target Type, then remove it firstly, or else an Exception will be thrown here 17 | if (SimpleIoc.Default.ContainsCreated()) 18 | { 19 | SimpleIoc.Default.Unregister(); 20 | } 21 | 22 | SimpleIoc.Default.Register(() => args); 23 | 24 | EditWindow editWindow = new EditWindow(); 25 | return editWindow.ShowDialog(); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /FriendEditor/Services/IDataProvider.cs: -------------------------------------------------------------------------------- 1 | using FriendEditor.Models; 2 | using System.Collections.Generic; 3 | 4 | namespace FriendEditor.Services 5 | { 6 | public interface IDataProvider 7 | { 8 | bool Delete(IFriend friend); 9 | 10 | List GetAllFriends(); 11 | 12 | IFriend GetFriendById(string id); 13 | 14 | bool Insert(IFriend friend); 15 | 16 | bool Update(IFriend friend); 17 | } 18 | } -------------------------------------------------------------------------------- /FriendEditor/Services/IDialogService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace FriendEditor.Services 4 | { 5 | public interface IDialogService 6 | { 7 | bool Confirm(string message); 8 | 9 | void ShowMessage(string message); 10 | 11 | void Warning(string message); 12 | 13 | void Exception(Exception ex); 14 | } 15 | } -------------------------------------------------------------------------------- /FriendEditor/Services/IEditWindowController.cs: -------------------------------------------------------------------------------- 1 | using FriendEditor.EventArgs; 2 | 3 | namespace FriendEditor.Services 4 | { 5 | public interface IEditWindowController 6 | { 7 | /// 8 | /// Show EditWindow 9 | /// 10 | /// 11 | /// 12 | bool? ShowDialog(OpenEditWindowArgs args); 13 | } 14 | } -------------------------------------------------------------------------------- /FriendEditor/Services/SqliteDataProvider.cs: -------------------------------------------------------------------------------- 1 | using FriendEditor.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Data; 5 | using System.Data.SQLite; 6 | using System.IO; 7 | 8 | namespace FriendEditor.Services 9 | { 10 | public class SqliteDataProvider : IDataProvider 11 | { 12 | #region Constants 13 | 14 | public const string FileName = "Friends.db"; 15 | 16 | #endregion Constants 17 | 18 | #region Constructors 19 | 20 | public SqliteDataProvider() 21 | { 22 | DataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, FileName); 23 | 24 | SQLiteConnectionStringBuilder builder = new SQLiteConnectionStringBuilder(); 25 | builder.DataSource = DataPath; 26 | ConnectionString = builder.ToString(); 27 | 28 | if (!File.Exists(DataPath)) 29 | { 30 | SQLiteConnection.CreateFile(DataPath); 31 | 32 | string sqlCreateTable = @"CREATE TABLE Friend( 33 | Id varchar(40) Primary Key, 34 | Name varchar(20) Not Null, 35 | Email varchar(20), 36 | IsDeveloper bool, 37 | BirthDate date)"; 38 | 39 | ExeNonQueryCommand(sqlCreateTable); 40 | } 41 | } 42 | 43 | #endregion Constructors 44 | 45 | #region Properties 46 | 47 | /// 48 | /// The full data path of the sqlite database file 49 | /// 50 | public string DataPath { get; private set; } 51 | 52 | /// 53 | /// The connection string 54 | /// 55 | protected string ConnectionString { get; set; } 56 | 57 | #endregion Properties 58 | 59 | #region Methods 60 | 61 | public bool Delete(IFriend friend) 62 | { 63 | string sqlDelete = $@"DELETE FROM Friend WHERE Id='{friend.Id}'"; 64 | return ExeNonQueryCommand(sqlDelete); 65 | } 66 | 67 | public List GetAllFriends() 68 | { 69 | var list = new List(); 70 | using (SQLiteConnection conn = new SQLiteConnection(ConnectionString)) 71 | { 72 | conn.Open(); 73 | string sqlInsert = $@"SELECT * FROM Friend"; 74 | using (SQLiteCommand cmd = new SQLiteCommand(sqlInsert, conn)) 75 | { 76 | using (SQLiteDataAdapter da = new SQLiteDataAdapter(cmd)) 77 | { 78 | var dataTable = new DataTable(); 79 | da.Fill(dataTable); 80 | 81 | foreach (DataRow row in dataTable.Rows) 82 | { 83 | var friend = new Friend(); 84 | friend.Id = row["Id"].ToString(); 85 | friend.Name = row["Name"].ToString(); 86 | friend.Email = row["Email"] != null ? row["Email"].ToString() : string.Empty; 87 | friend.IsDeveloper = row["IsDeveloper"] != null ? (bool)(row["IsDeveloper"]) : false; 88 | friend.BirthDate = row["BirthDate"] != null ? (DateTime)(row["BirthDate"]) : DateTime.MinValue; 89 | list.Add(friend); 90 | } 91 | } 92 | } 93 | } 94 | 95 | return list; 96 | } 97 | 98 | public IFriend GetFriendById(string id) 99 | { 100 | Friend friend = null; 101 | using (SQLiteConnection conn = new SQLiteConnection(ConnectionString)) 102 | { 103 | conn.Open(); 104 | string sqlInsert = $@"SELECT * FROM Friend WHERE Id='{id}'"; 105 | using (SQLiteCommand cmd = new SQLiteCommand(sqlInsert, conn)) 106 | { 107 | SQLiteDataReader dr = cmd.ExecuteReader(); 108 | if (dr.Read()) 109 | { 110 | friend = new Friend(); 111 | friend.Id = dr["Id"].ToString(); 112 | friend.Name = dr["Name"].ToString(); 113 | friend.Email = dr["Email"] != null ? dr["Email"].ToString() : string.Empty; 114 | friend.IsDeveloper = dr["IsDeveloper"] != null ? (bool)(dr["IsDeveloper"]) : false; 115 | friend.BirthDate = dr["BirthDate"] != null ? (DateTime)(dr["BirthDate"]) : DateTime.MinValue; 116 | } 117 | } 118 | } 119 | 120 | return friend; 121 | } 122 | 123 | public bool Insert(IFriend friend) 124 | { 125 | string sqlInsert = $@"INSERT INTO Friend VALUES('{friend.Id}','{friend.Name}','{friend.Email}','{friend.IsDeveloper}','{friend.BirthDate.ToString("s")}')"; 126 | return ExeNonQueryCommand(sqlInsert); 127 | } 128 | 129 | public bool Update(IFriend friend) 130 | { 131 | string sqlUpdate = $@"UPDATE Friend SET Name='{friend.Name}', Email='{friend.Email}', IsDeveloper='{friend.IsDeveloper}', BirthDate='{friend.BirthDate.ToString("s")}' WHERE Id='{friend.Id}'"; 132 | return ExeNonQueryCommand(sqlUpdate); 133 | } 134 | 135 | private bool ExeNonQueryCommand(string sqlCommandText) 136 | { 137 | bool isSuccess = false; 138 | 139 | using (SQLiteConnection conn = new SQLiteConnection(ConnectionString)) 140 | { 141 | conn.Open(); 142 | 143 | using (SQLiteCommand cmd = new SQLiteCommand(sqlCommandText, conn)) 144 | { 145 | isSuccess = cmd.ExecuteNonQuery() > 0 ? true : false; 146 | } 147 | } 148 | 149 | return isSuccess; 150 | } 151 | 152 | #endregion Methods 153 | } 154 | } -------------------------------------------------------------------------------- /FriendEditor/ViewModels/EditViewModel.cs: -------------------------------------------------------------------------------- 1 | using FriendEditor.EventArgs; 2 | using FriendEditor.Models; 3 | using FriendEditor.Services; 4 | using GalaSoft.MvvmLight; 5 | using GalaSoft.MvvmLight.Command; 6 | using GalaSoft.MvvmLight.Messaging; 7 | using System; 8 | 9 | namespace FriendEditor.ViewModels 10 | { 11 | public class EditViewModel : ViewModelBase 12 | { 13 | #region Constructors 14 | 15 | public EditViewModel(OpenEditWindowArgs args, IDataProvider dataProvider, IDialogService dialogService) 16 | { 17 | Args = args; 18 | DataProvider = dataProvider; 19 | DialogService = dialogService; 20 | 21 | switch (args.Type) 22 | { 23 | case ActionType.Add: 24 | CurrentFriend = new Friend { Id = Guid.NewGuid().ToString(), BirthDate = new DateTime(1990, 1, 1) }; 25 | break; 26 | 27 | case ActionType.Edit: 28 | // Clone a new object 29 | CurrentFriend = new Friend 30 | { 31 | Id = args.Friend.Id, 32 | Name = args.Friend.Name, 33 | BirthDate = args.Friend.BirthDate, 34 | Email = args.Friend.Email, 35 | IsDeveloper = args.Friend.IsDeveloper 36 | }; 37 | break; 38 | } 39 | 40 | SaveDataCommand = new RelayCommand(SaveData); 41 | } 42 | 43 | #endregion Constructors 44 | 45 | #region Properties 46 | 47 | public Friend CurrentFriend { get; set; } 48 | public IDataProvider DataProvider { get; } 49 | public IDialogService DialogService { get; set; } 50 | public RelayCommand SaveDataCommand { get; set; } 51 | protected OpenEditWindowArgs Args { get; } 52 | 53 | #endregion Properties 54 | 55 | #region Methods 56 | 57 | private void SaveData() 58 | { 59 | if (string.IsNullOrWhiteSpace(CurrentFriend.Name)) 60 | { 61 | DialogService.Warning("Name is required"); 62 | return; 63 | } 64 | 65 | bool result = false; 66 | switch (Args.Type) 67 | { 68 | case ActionType.Add: 69 | result = DataProvider.Insert(CurrentFriend); 70 | 71 | break; 72 | 73 | case ActionType.Edit: 74 | result = DataProvider.Update(CurrentFriend); 75 | break; 76 | } 77 | 78 | if (result) 79 | { 80 | DialogService.ShowMessage($"{Args.Type} friend successfully"); 81 | 82 | // Send a message to Close the current View(EditWindow) 83 | Messenger.Default.Send(new CloseWindowEventArgs()); 84 | } 85 | else 86 | { 87 | DialogService.Warning($"Error occured, save data failed"); 88 | } 89 | } 90 | 91 | #endregion Methods 92 | } 93 | } -------------------------------------------------------------------------------- /FriendEditor/ViewModels/MainViewModel.cs: -------------------------------------------------------------------------------- 1 | using FriendEditor.EventArgs; 2 | using FriendEditor.Models; 3 | using FriendEditor.Services; 4 | using GalaSoft.MvvmLight; 5 | using GalaSoft.MvvmLight.Command; 6 | using System.Collections.ObjectModel; 7 | using System.Linq; 8 | 9 | namespace FriendEditor.ViewModels 10 | { 11 | public class MainViewModel : ViewModelBase 12 | { 13 | #region Variables 14 | 15 | private ObservableCollection _allFriends; 16 | private Friend _selectedFriend; 17 | 18 | #endregion Variables 19 | 20 | #region Constructors 21 | 22 | public MainViewModel(IDataProvider dataProvider, IEditWindowController editWindowController, IDialogService dialogService) 23 | { 24 | DataProvider = dataProvider; 25 | EditWindowController = editWindowController; 26 | DialogService = dialogService; 27 | 28 | AddFriendCommand = new RelayCommand(AddFriend); 29 | EditFriendCommand = new RelayCommand(EditFriend, friend => SelectedFriend != null); 30 | DeleteFriendCommand = new RelayCommand(DeleteFriend, friend => SelectedFriend != null); 31 | 32 | AllFriends = new ObservableCollection(dataProvider.GetAllFriends().OfType()); 33 | } 34 | 35 | #endregion Constructors 36 | 37 | #region Properties 38 | 39 | public RelayCommand AddFriendCommand { get; set; } 40 | 41 | /// 42 | /// Get or set AllFriends value 43 | /// 44 | public ObservableCollection AllFriends 45 | { 46 | get { return _allFriends; } 47 | set { Set(ref _allFriends, value); } 48 | } 49 | 50 | public IDataProvider DataProvider { get; } 51 | public RelayCommand DeleteFriendCommand { get; set; } 52 | public IDialogService DialogService { get; } 53 | public RelayCommand EditFriendCommand { get; set; } 54 | public IEditWindowController EditWindowController { get; } 55 | 56 | /// 57 | /// Get or set SelectedFriend value 58 | /// 59 | public Friend SelectedFriend 60 | { 61 | get { return _selectedFriend; } 62 | set 63 | { 64 | Set(ref _selectedFriend, value); 65 | 66 | // If SelectedFriend property changed, check if Edit&Delete commands can execute 67 | DeleteFriendCommand.RaiseCanExecuteChanged(); 68 | EditFriendCommand.RaiseCanExecuteChanged(); 69 | } 70 | } 71 | 72 | #endregion Properties 73 | 74 | #region Methods 75 | 76 | private void AddFriend() 77 | { 78 | var result = EditWindowController.ShowDialog(new OpenEditWindowArgs { Type = ActionType.Add }); 79 | if (result.HasValue && result.Value) 80 | { 81 | AllFriends = new ObservableCollection(DataProvider.GetAllFriends().OfType()); 82 | } 83 | } 84 | 85 | private void DeleteFriend(Friend friend) 86 | { 87 | if (DialogService.Confirm("Really want to delete this friend?")) 88 | { 89 | AllFriends.Remove(friend); 90 | DataProvider.Delete(friend); 91 | DialogService.ShowMessage("Delete friend successfully"); 92 | } 93 | } 94 | 95 | private void EditFriend(Friend friend) 96 | { 97 | var result = EditWindowController.ShowDialog(new OpenEditWindowArgs { Type = ActionType.Edit, Friend = SelectedFriend }); 98 | if (result.HasValue && result.Value) 99 | { 100 | // Remember user's selection 101 | int index = AllFriends.IndexOf(SelectedFriend); 102 | AllFriends = new ObservableCollection(DataProvider.GetAllFriends().OfType()); 103 | 104 | // re-selected the original item 105 | SelectedFriend = AllFriends[index]; 106 | } 107 | } 108 | 109 | #endregion Methods 110 | } 111 | } -------------------------------------------------------------------------------- /FriendEditor/ViewModels/ViewModelLocator.cs: -------------------------------------------------------------------------------- 1 | using GalaSoft.MvvmLight.Ioc; 2 | using System; 3 | 4 | namespace FriendEditor.ViewModels 5 | { 6 | public class ViewModelLocator 7 | { 8 | public ViewModelLocator() 9 | { 10 | SimpleIoc.Default.Register(); 11 | SimpleIoc.Default.Register(); 12 | } 13 | 14 | public EditViewModel EditViewModel => SimpleIoc.Default.GetInstance(Guid.NewGuid().ToString()); 15 | public MainViewModel MainViewModel => SimpleIoc.Default.GetInstance(Guid.NewGuid().ToString()); 16 | } 17 | } -------------------------------------------------------------------------------- /FriendEditor/Views/EditWindow.xaml: -------------------------------------------------------------------------------- 1 |  17 | 18 | 19 | 0,10,0,0 20 | 21 | 22 | 23 | 28 | 29 | 30 | 35 | 36 | 41 | 42 | 43 | 47 | 48 | 52 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /FriendEditor/Views/EditWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using FriendEditor.EventArgs; 2 | using GalaSoft.MvvmLight.Messaging; 3 | using System.Windows; 4 | 5 | namespace FriendEditor.Views 6 | { 7 | /// 8 | /// Interaction logic for EditWindow.xaml 9 | /// 10 | public partial class EditWindow : Window 11 | { 12 | public EditWindow() 13 | { 14 | InitializeComponent(); 15 | Unloaded += EditWindow_Unloaded; 16 | Messenger.Default.Register(this, CloseWindow); 17 | } 18 | 19 | private void CloseWindow(CloseWindowEventArgs obj) 20 | { 21 | this.DialogResult = true; 22 | this.Close(); 23 | } 24 | 25 | private void EditWindow_Unloaded(object sender, RoutedEventArgs e) 26 | { 27 | Messenger.Default.Unregister(this); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /FriendEditor/Views/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 45 | 46 | 47 | 48 | 49 | 50 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 |