Add project files.
This commit is contained in:
25
QuickMVVMSetup.sln
Normal file
25
QuickMVVMSetup.sln
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.2.32630.192
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickMVVMSetup", "QuickMVVMSetup\QuickMVVMSetup.csproj", "{ABD27BDD-F092-4031-9233-1D09D67B639E}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{ABD27BDD-F092-4031-9233-1D09D67B639E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{ABD27BDD-F092-4031-9233-1D09D67B639E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{ABD27BDD-F092-4031-9233-1D09D67B639E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{ABD27BDD-F092-4031-9233-1D09D67B639E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {53E0FF96-FCE2-449B-9D8F-1892D63E50EF}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
30
QuickMVVMSetup/AddCommand.cs
Normal file
30
QuickMVVMSetup/AddCommand.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Input;
|
||||||
|
|
||||||
|
namespace QuickMVVMSetup
|
||||||
|
{
|
||||||
|
public class AddCommand : ICommand
|
||||||
|
{
|
||||||
|
public event EventHandler? CanExecuteChanged;
|
||||||
|
public MainVM assosiatedVM;
|
||||||
|
|
||||||
|
public bool CanExecute(object parameter)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Execute(object parameter)
|
||||||
|
{
|
||||||
|
assosiatedVM.AddPerson();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AddCommand(MainVM vm)
|
||||||
|
{
|
||||||
|
assosiatedVM = vm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
QuickMVVMSetup/App.xaml
Normal file
9
QuickMVVMSetup/App.xaml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<Application x:Class="QuickMVVMSetup.App"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:local="clr-namespace:QuickMVVMSetup"
|
||||||
|
StartupUri="MainWindow.xaml">
|
||||||
|
<Application.Resources>
|
||||||
|
|
||||||
|
</Application.Resources>
|
||||||
|
</Application>
|
||||||
17
QuickMVVMSetup/App.xaml.cs
Normal file
17
QuickMVVMSetup/App.xaml.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
namespace QuickMVVMSetup
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for App.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class App : Application
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
10
QuickMVVMSetup/AssemblyInfo.cs
Normal file
10
QuickMVVMSetup/AssemblyInfo.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
[assembly: ThemeInfo(
|
||||||
|
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||||
|
//(used if a resource is not found in the page,
|
||||||
|
// or application resource dictionaries)
|
||||||
|
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||||
|
//(used if a resource is not found in the page,
|
||||||
|
// app, or any theme specific resource dictionaries)
|
||||||
|
)]
|
||||||
20
QuickMVVMSetup/ChangeNotifier.cs
Normal file
20
QuickMVVMSetup/ChangeNotifier.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
|
||||||
|
namespace QuickMVVMSetup
|
||||||
|
{
|
||||||
|
public class ChangeNotifier : INotifyPropertyChanged
|
||||||
|
{
|
||||||
|
public event PropertyChangedEventHandler? PropertyChanged;
|
||||||
|
protected void OnPropertyChanged(string propName)
|
||||||
|
{
|
||||||
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
47
QuickMVVMSetup/MainVM.cs
Normal file
47
QuickMVVMSetup/MainVM.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
|
||||||
|
namespace QuickMVVMSetup;
|
||||||
|
|
||||||
|
public class MainVM : ChangeNotifier
|
||||||
|
{
|
||||||
|
|
||||||
|
private Person person;
|
||||||
|
|
||||||
|
public Person TargetPerson
|
||||||
|
{
|
||||||
|
get { return person; }
|
||||||
|
set { person = value; OnPropertyChanged(nameof(TargetPerson)); }
|
||||||
|
}
|
||||||
|
|
||||||
|
private ObservableCollection<Person> _persons; //only when added/or removed (not for internal property changes)
|
||||||
|
|
||||||
|
public ObservableCollection<Person> Persons
|
||||||
|
{
|
||||||
|
get { return _persons; }
|
||||||
|
set { _persons = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddPerson(object person)
|
||||||
|
{
|
||||||
|
Persons.Add(TargetPerson); // Adding to collection
|
||||||
|
TargetPerson = new Person(); //Resetting it
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//public ICommand CMDAdd { get; set; }
|
||||||
|
public ICommand CMDAdd => new RelayCommand(AddPerson,null);
|
||||||
|
|
||||||
|
public MainVM()
|
||||||
|
{
|
||||||
|
//CMDAdd = new AddCommand(this);
|
||||||
|
//TargetPerson = new Person();
|
||||||
|
Persons = new ObservableCollection<Person>();
|
||||||
|
}
|
||||||
|
}
|
||||||
69
QuickMVVMSetup/MainWindow.xaml
Normal file
69
QuickMVVMSetup/MainWindow.xaml
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<Window x:Class="QuickMVVMSetup.MainWindow"
|
||||||
|
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:local="clr-namespace:QuickMVVMSetup"
|
||||||
|
mc:Ignorable="d" WindowStartupLocation="CenterScreen"
|
||||||
|
Title="MainWindow" Height="450" Width="400">
|
||||||
|
<Window.Resources>
|
||||||
|
<ResourceDictionary>
|
||||||
|
<Style TargetType="{x:Type ItemsControl}">
|
||||||
|
<Setter Property="Margin" Value="5"/>
|
||||||
|
<Setter Property="ItemsPanel">
|
||||||
|
<Setter.Value>
|
||||||
|
<ItemsPanelTemplate>
|
||||||
|
<Grid>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition />
|
||||||
|
<ColumnDefinition />
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
</Grid>
|
||||||
|
</ItemsPanelTemplate>
|
||||||
|
</Setter.Value>
|
||||||
|
</Setter>
|
||||||
|
</Style>
|
||||||
|
</ResourceDictionary>
|
||||||
|
</Window.Resources>
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition/>
|
||||||
|
<RowDefinition/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<StackPanel Margin="10">
|
||||||
|
<ItemsControl>
|
||||||
|
<TextBlock Text="First Name" />
|
||||||
|
<TextBox Grid.Column="1" Text="{Binding TargetPerson.FName}"/>
|
||||||
|
</ItemsControl>
|
||||||
|
<ItemsControl>
|
||||||
|
<TextBlock Text="Last Name" />
|
||||||
|
<TextBox Grid.Column="1" Text="{Binding TargetPerson.LName}"/>
|
||||||
|
</ItemsControl>
|
||||||
|
<ItemsControl>
|
||||||
|
<TextBlock Text="Age" />
|
||||||
|
<TextBox Grid.Column="1" Text="{Binding TargetPerson.Age}"/>
|
||||||
|
</ItemsControl>
|
||||||
|
<Button Content="Add" Height="30" Width="120" Margin="5, 20" HorizontalAlignment="Right" Command="{Binding CMDAdd}"/>
|
||||||
|
</StackPanel>
|
||||||
|
<ListView Grid.Row="1" Background="#FFDBEFCA" ItemsSource="{Binding Persons}">
|
||||||
|
<ListView.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<TextBlock Text="{Binding FName}" />
|
||||||
|
<TextBlock Text=" - " Foreground="Blue" />
|
||||||
|
<TextBlock Text="{Binding LName}" />
|
||||||
|
<TextBlock Text=" - " Foreground="Blue" />
|
||||||
|
<TextBlock Text="{Binding Age}" />
|
||||||
|
</StackPanel>
|
||||||
|
</DataTemplate>
|
||||||
|
</ListView.ItemTemplate>
|
||||||
|
<!--<WrapPanel>
|
||||||
|
<TextBlock Text="First Name" />
|
||||||
|
<TextBlock Text=" - " Foreground="Blue" />
|
||||||
|
<TextBlock Text="Last Name" />
|
||||||
|
<TextBlock Text=" - " Foreground="Blue" />
|
||||||
|
<TextBlock Text="Age" />
|
||||||
|
</WrapPanel>-->
|
||||||
|
</ListView>
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
31
QuickMVVMSetup/MainWindow.xaml.cs
Normal file
31
QuickMVVMSetup/MainWindow.xaml.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
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 QuickMVVMSetup
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for MainWindow.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class MainWindow : Window
|
||||||
|
{
|
||||||
|
public MainWindow()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
DataContext = new MainVM(); //Connecting view with viewmodel
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
39
QuickMVVMSetup/Person.cs
Normal file
39
QuickMVVMSetup/Person.cs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace QuickMVVMSetup
|
||||||
|
{
|
||||||
|
public class Person : ChangeNotifier
|
||||||
|
{
|
||||||
|
//poco model & dto model
|
||||||
|
|
||||||
|
private string _FName;
|
||||||
|
|
||||||
|
public string FName
|
||||||
|
{
|
||||||
|
get { return _FName; }
|
||||||
|
set { _FName = value; OnPropertyChanged(nameof(FName)); }
|
||||||
|
}
|
||||||
|
|
||||||
|
private string _LName;
|
||||||
|
|
||||||
|
public string LName
|
||||||
|
{
|
||||||
|
get { return _LName; }
|
||||||
|
set { _LName = value; OnPropertyChanged(nameof(LName)); }
|
||||||
|
}
|
||||||
|
|
||||||
|
private string _Age;
|
||||||
|
|
||||||
|
public string Age
|
||||||
|
{
|
||||||
|
get { return _Age; }
|
||||||
|
set { _Age = value; OnPropertyChanged(nameof(Age)); }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
14
QuickMVVMSetup/QuickMVVMSetup.csproj
Normal file
14
QuickMVVMSetup/QuickMVVMSetup.csproj
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<UseWPF>true</UseWPF>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Remove="AddCommand.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
35
QuickMVVMSetup/RelayCommand.cs
Normal file
35
QuickMVVMSetup/RelayCommand.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Input;
|
||||||
|
|
||||||
|
namespace QuickMVVMSetup
|
||||||
|
{
|
||||||
|
public class RelayCommand : ICommand
|
||||||
|
{
|
||||||
|
public event EventHandler? CanExecuteChanged;
|
||||||
|
private Action<object> _executeAction;
|
||||||
|
private Func<object, bool> _canExecuteAction;
|
||||||
|
public bool CanExecute(object? parameter)
|
||||||
|
{
|
||||||
|
if (_canExecuteAction == null)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return _canExecuteAction.Invoke(parameter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Execute(object? parameter)
|
||||||
|
{
|
||||||
|
_executeAction.Invoke(parameter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RelayCommand(Action<object> executeAction, Func<object, bool> canExecuteFunc)
|
||||||
|
{
|
||||||
|
_executeAction = executeAction;
|
||||||
|
_canExecuteAction = canExecuteFunc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user