-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54a5d5e
commit 94a8624
Showing
31 changed files
with
443 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using WPF.MVVM.Navigation.Services; | ||
using WPF.MVVM.Navigation.Stores; | ||
using WPF.MVVM.Navigation.ViewModels; | ||
|
||
namespace WPF.MVVM.Navigation.Commands | ||
{ | ||
public class CreatePersonCommand : CommandBase | ||
{ | ||
#region Fields | ||
private readonly CreatePersonViewModel _createPersonViewModel; | ||
private INavigationService _navigationService; | ||
private readonly PeopleStore _peopleStore; | ||
#endregion | ||
|
||
#region Constructor | ||
public CreatePersonCommand(CreatePersonViewModel createPersonViewModel, INavigationService navigationService, PeopleStore peopleStore) | ||
{ | ||
_createPersonViewModel = createPersonViewModel; | ||
_navigationService = navigationService; | ||
_peopleStore = peopleStore; | ||
} | ||
#endregion | ||
|
||
#region CommandBase | ||
public override void Execute(object? parameter) | ||
{ | ||
string name = _createPersonViewModel.Name; | ||
_peopleStore.Create(name); | ||
|
||
_navigationService.Navigate(); | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
|
||
namespace WPF.MVVM.Navigation.Stores | ||
{ | ||
public class PeopleStore | ||
{ | ||
#region Events | ||
public event Action<string> PersonCreated; | ||
#endregion | ||
|
||
#region Helper methods | ||
public void Create(string name) | ||
{ | ||
PersonCreated?.Invoke(name); | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Windows.Input; | ||
using WPF.MVVM.Navigation.Commands; | ||
using WPF.MVVM.Navigation.Services; | ||
using WPF.MVVM.Navigation.Stores; | ||
|
||
namespace WPF.MVVM.Navigation.ViewModels | ||
{ | ||
public class CreatePersonViewModel : ViewModelBase | ||
{ | ||
#region Properties | ||
private string _name; | ||
|
||
public string Name | ||
{ | ||
get { return _name; } | ||
set { _name = value; } | ||
} | ||
|
||
public ICommand SubmitCommand { get; } | ||
public ICommand CancelCommand { get; } | ||
#endregion | ||
|
||
#region Constructor | ||
public CreatePersonViewModel(INavigationService cancelNavigationService, PeopleStore peopleStore) | ||
{ | ||
SubmitCommand = new CreatePersonCommand(this, cancelNavigationService, peopleStore); | ||
CancelCommand = new NavigateCommand(cancelNavigationService); | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
WPF.MVVM.Navigation/ViewModels/PeopleListingItemViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using WPF.MVVM.Navigation.Stores; | ||
|
||
namespace WPF.MVVM.Navigation.ViewModels | ||
{ | ||
public class PeopleListingItemViewModel : ViewModelBase | ||
{ | ||
#region Properties | ||
public string Name { get; } | ||
#endregion | ||
|
||
#region Constructor | ||
public PeopleListingItemViewModel(string name) | ||
{ | ||
Name = name; | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Windows.Input; | ||
using System.Xml.Linq; | ||
using WPF.MVVM.Navigation.Commands; | ||
using WPF.MVVM.Navigation.Services; | ||
using WPF.MVVM.Navigation.Stores; | ||
|
||
namespace WPF.MVVM.Navigation.ViewModels | ||
{ | ||
public class PeopleListingViewModel : ViewModelBase | ||
{ | ||
#region Fields | ||
private readonly ObservableCollection<PeopleListingItemViewModel> _peopleListingItemViewModel; | ||
private readonly PeopleStore _peopleStore; | ||
#endregion | ||
|
||
#region Properties | ||
public IEnumerable<PeopleListingItemViewModel> PeopleListingItemViewModel => _peopleListingItemViewModel; | ||
public ICommand CreatePersonCommand { get; } | ||
#endregion | ||
|
||
#region Constructor | ||
public PeopleListingViewModel(INavigationService createPersonNavigationService, PeopleStore peopleStore) | ||
{ | ||
_peopleListingItemViewModel = new ObservableCollection<PeopleListingItemViewModel>(); | ||
_peopleStore = peopleStore; | ||
|
||
CreatePersonCommand = new NavigateCommand(createPersonNavigationService); | ||
|
||
_peopleListingItemViewModel.Add(new PeopleListingItemViewModel("a")); | ||
_peopleListingItemViewModel.Add(new PeopleListingItemViewModel("b")); | ||
_peopleListingItemViewModel.Add(new PeopleListingItemViewModel("c")); | ||
|
||
_peopleStore.PersonCreated += PeopleStore_PersonCreated; | ||
} | ||
|
||
#region PersonCreated Subscribed | ||
private void PeopleStore_PersonCreated(string name) | ||
{ | ||
_peopleListingItemViewModel.Add(new PeopleListingItemViewModel(name)); | ||
} | ||
#endregion | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<UserControl | ||
x:Class="WPF.MVVM.Navigation.Views.CreatePersonView" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:WPF.MVVM.Navigation.Views" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
d:DesignHeight="450" | ||
d:DesignWidth="800" | ||
mc:Ignorable="d"> | ||
<Grid Margin="20"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="auto" /> | ||
<RowDefinition Height="auto" /> | ||
<RowDefinition Height="auto" /> | ||
</Grid.RowDefinitions> | ||
|
||
<TextBlock | ||
Grid.Row="0" | ||
FontSize="28" | ||
Text="Add Person" /> | ||
|
||
<Grid Grid.Row="1" Margin="0,20,0,0"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="auto" /> | ||
<RowDefinition Height="auto" /> | ||
</Grid.RowDefinitions> | ||
|
||
<TextBlock Grid.Row="0" Text="Name" /> | ||
<TextBox | ||
Grid.Row="1" | ||
Margin="0,5,0,0" | ||
Text="{Binding Name}" /> | ||
</Grid> | ||
|
||
<WrapPanel Grid.Row="2" Margin="0,20,0,0"> | ||
<Button | ||
Width="100" | ||
Height="30" | ||
Command="{Binding SubmitCommand}" | ||
Content="Submit" /> | ||
<Button | ||
Width="150" | ||
Height="30" | ||
Margin="20,0,0,0" | ||
Command="{Binding CancelCommand}" | ||
Content="Cancel" /> | ||
</WrapPanel> | ||
</Grid> | ||
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Navigation; | ||
using System.Windows.Shapes; | ||
|
||
namespace WPF.MVVM.Navigation.Views | ||
{ | ||
/// <summary> | ||
/// Interaction logic for CreatePersonView.xaml | ||
/// </summary> | ||
public partial class CreatePersonView : UserControl | ||
{ | ||
public CreatePersonView() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
Oops, something went wrong.