diff --git a/App.xaml b/App.xaml new file mode 100644 index 0000000..cb15d5b --- /dev/null +++ b/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/App.xaml.cs b/App.xaml.cs new file mode 100644 index 0000000..45b4126 --- /dev/null +++ b/App.xaml.cs @@ -0,0 +1,14 @@ +using System.Configuration; +using System.Data; +using System.Windows; + +namespace MVVM_DEMO +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } + +} diff --git a/AssemblyInfo.cs b/AssemblyInfo.cs new file mode 100644 index 0000000..b0ec827 --- /dev/null +++ b/AssemblyInfo.cs @@ -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) +)] diff --git a/MVVM_DEMO.csproj b/MVVM_DEMO.csproj new file mode 100644 index 0000000..c4da95b --- /dev/null +++ b/MVVM_DEMO.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net8.0-windows + enable + enable + true + + + + + + + diff --git a/MVVM_DEMO.sln b/MVVM_DEMO.sln new file mode 100644 index 0000000..da839ef --- /dev/null +++ b/MVVM_DEMO.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.13.35919.96 d17.13 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MVVM_DEMO", "MVVM_DEMO.csproj", "{FBB9EB22-3115-4366-8C35-A300DA922B06}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FBB9EB22-3115-4366-8C35-A300DA922B06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FBB9EB22-3115-4366-8C35-A300DA922B06}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FBB9EB22-3115-4366-8C35-A300DA922B06}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FBB9EB22-3115-4366-8C35-A300DA922B06}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A0C2E5CF-A025-4D96-B992-801A8719AA75} + EndGlobalSection +EndGlobal diff --git a/Models/Product.cs b/Models/Product.cs new file mode 100644 index 0000000..56bb692 --- /dev/null +++ b/Models/Product.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MVVM_DEMO.Models +{ + public class Product + { + public string ProductName { get; set; } + public double Price { get; set; } + + } +} diff --git a/ViewModels/MainViewModel.cs b/ViewModels/MainViewModel.cs new file mode 100644 index 0000000..6499a0b --- /dev/null +++ b/ViewModels/MainViewModel.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MVVM_DEMO.Models; + +namespace MVVM_DEMO.ViewModels +{ + public class MainViewModel : INotifyPropertyChanged + { + + + private ObservableCollection _products; + + public event PropertyChangedEventHandler? PropertyChanged; + + public void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + // constructor + + public MainViewModel() + { + _products = new ObservableCollection(); + LoadData(); + } + + // read data + private void LoadData() + { + _products.Add(new Product { ProductName = "Product 1", Price = 10.0 }); + _products.Add(new Product { ProductName = "Product 2", Price = 20.0 }); + _products.Add(new Product { ProductName = "Product 3", Price = 30.0 }); + Products = _products; + } + + + // properties + public ObservableCollection Products { get; set; } + + public string productName { get; set; } + public int productPrice { get; set; } + + } +} diff --git a/Views/MainWindow.xaml b/Views/MainWindow.xaml new file mode 100644 index 0000000..21f4ec2 --- /dev/null +++ b/Views/MainWindow.xaml @@ -0,0 +1,45 @@ + + + + + + + + +