├── App.xaml
├── App.xaml.cs
├── Fonts
├── BarlowCondensed-Regular.ttf
└── Roboto-Regular.ttf
├── Images
├── closed.png
├── open.png
├── shutdown_def.png
└── shutdown_mo.png
├── LICENSE
├── MainWindow.xaml
├── MainWindow.xaml.cs
├── README.md
├── Services
├── IWindowService.cs
└── WindowService.cs
├── Source Code
└── MVVM Window App.rar
├── Utilities
└── RelayCommand.cs
├── View
├── NewWindow.xaml
└── NewWindow.xaml.cs
└── ViewModel
└── MainViewModel.cs
/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
12 |
13 |
16 |
17 |
70 |
71 |
124 |
125 |
144 |
145 |
164 |
165 |
185 |
186 |
204 |
205 |
224 |
225 |
244 |
245 |
246 |
247 |
250 |
251 |
254 |
255 |
308 |
309 |
310 |
311 |
312 |
--------------------------------------------------------------------------------
/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 MVVM_Window_App
10 | {
11 | ///
12 | /// Interaction logic for App.xaml
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Fonts/BarlowCondensed-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpDesignPro/WPF---Open-a-New-Window-in-MVVM/8336191d3065c6c6d04f85b653af2ddb2bdfc1d6/Fonts/BarlowCondensed-Regular.ttf
--------------------------------------------------------------------------------
/Fonts/Roboto-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpDesignPro/WPF---Open-a-New-Window-in-MVVM/8336191d3065c6c6d04f85b653af2ddb2bdfc1d6/Fonts/Roboto-Regular.ttf
--------------------------------------------------------------------------------
/Images/closed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpDesignPro/WPF---Open-a-New-Window-in-MVVM/8336191d3065c6c6d04f85b653af2ddb2bdfc1d6/Images/closed.png
--------------------------------------------------------------------------------
/Images/open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpDesignPro/WPF---Open-a-New-Window-in-MVVM/8336191d3065c6c6d04f85b653af2ddb2bdfc1d6/Images/open.png
--------------------------------------------------------------------------------
/Images/shutdown_def.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpDesignPro/WPF---Open-a-New-Window-in-MVVM/8336191d3065c6c6d04f85b653af2ddb2bdfc1d6/Images/shutdown_def.png
--------------------------------------------------------------------------------
/Images/shutdown_mo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpDesignPro/WPF---Open-a-New-Window-in-MVVM/8336191d3065c6c6d04f85b653af2ddb2bdfc1d6/Images/shutdown_mo.png
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Arun Mutharasu
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 |
--------------------------------------------------------------------------------
/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using MVVM_Window_App.Services;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 | using System.Windows.Controls;
9 | using System.Windows.Data;
10 | using System.Windows.Documents;
11 | using System.Windows.Input;
12 | using System.Windows.Media;
13 | using System.Windows.Media.Imaging;
14 | using System.Windows.Navigation;
15 | using System.Windows.Shapes;
16 | using MVVM_Window_App.ViewModel;
17 |
18 | namespace MVVM_Window_App
19 | {
20 | ///
21 | /// Interaction logic for MainWindow.xaml
22 | ///
23 | public partial class MainWindow : Window
24 | {
25 | public MainWindow()
26 | {
27 | InitializeComponent();
28 |
29 | // Create an instance of the WindowService
30 | var windowService = new WindowService();
31 |
32 | // Set the data context for the main window to a new instance of the ViewModel,
33 | // passing in the WindowService as a dependency
34 | DataContext = new MainViewModel(windowService);
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WPF - Open a New Window in MVVM
2 |
3 | 
4 |
5 | YouTube Video Tutorial Link : https://youtu.be/3WeXjhc-TM8
6 |
7 | Icon Credits : https://icons8.com/icons
8 |
--------------------------------------------------------------------------------
/Services/IWindowService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace MVVM_Window_App.Services
8 | {
9 | public interface IWindowService
10 | {
11 | void OpenWindow();
12 | void CloseWindow();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Services/WindowService.cs:
--------------------------------------------------------------------------------
1 | using MVVM_Window_App.View;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace MVVM_Window_App.Services
10 | {
11 | public class WindowService : IWindowService
12 | {
13 | public void OpenWindow()
14 | {
15 | // Create an instance of the new window
16 | var window = new NewWindow();
17 |
18 | // Show the new window
19 | window.ShowDialog();
20 | }
21 |
22 | public void CloseWindow()
23 | {
24 | // Get a reference to the current window
25 | var window = Application.Current.Windows.OfType().SingleOrDefault(x => x.IsActive);
26 |
27 | // Close the window
28 | if (window != null)
29 | {
30 | window.Close();
31 | }
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Source Code/MVVM Window App.rar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpDesignPro/WPF---Open-a-New-Window-in-MVVM/8336191d3065c6c6d04f85b653af2ddb2bdfc1d6/Source Code/MVVM Window App.rar
--------------------------------------------------------------------------------
/Utilities/RelayCommand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows.Input;
7 |
8 | namespace Open_Window_Trial_1.Utilities
9 | {
10 | public class RelayCommand : ICommand
11 | {
12 | private readonly Action