Student handleiding added
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -8,8 +10,35 @@ namespace MVVM_DEMO.Models
|
||||
{
|
||||
public class Product
|
||||
{
|
||||
public string ProductName { get; set; }
|
||||
public double Price { get; set; }
|
||||
private string _productName;
|
||||
private decimal _productPrice;
|
||||
|
||||
public string ProductName
|
||||
{
|
||||
get => _productName;
|
||||
set
|
||||
{
|
||||
_productName = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public decimal ProductPrice
|
||||
{
|
||||
get => _productPrice;
|
||||
set
|
||||
{
|
||||
_productPrice = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
1617
STUDENT_HANDLEIDING.md
Normal file
1617
STUDENT_HANDLEIDING.md
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,13 +1,14 @@
|
||||
using System;
|
||||
using MVVM_DEMO.Commands;
|
||||
using MVVM_DEMO.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using MVVM_DEMO.Commands;
|
||||
using MVVM_DEMO.Models;
|
||||
|
||||
namespace MVVM_DEMO.ViewModels
|
||||
{
|
||||
@@ -16,10 +17,11 @@ namespace MVVM_DEMO.ViewModels
|
||||
|
||||
|
||||
private ObservableCollection<Product> _products;
|
||||
private Product _selectedProduct;
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public void OnPropertyChanged(string propertyName)
|
||||
public void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
@@ -38,18 +40,33 @@ namespace MVVM_DEMO.ViewModels
|
||||
// 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.Add(new Product { ProductName = "Product 1",ProductPrice = 10 });
|
||||
_products.Add(new Product { ProductName = "Product 2", ProductPrice = 20 });
|
||||
_products.Add(new Product { ProductName = "Product 3", ProductPrice = 30 });
|
||||
Products = _products;
|
||||
}
|
||||
|
||||
|
||||
// properties
|
||||
public ObservableCollection<Product> Products { get; set; }
|
||||
public ObservableCollection<Product> Products
|
||||
{
|
||||
get => _products;
|
||||
set
|
||||
{
|
||||
_products = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public string productName { get; set; }
|
||||
public int productPrice { get; set; }
|
||||
public Product SelectedProduct
|
||||
{
|
||||
get => _selectedProduct;
|
||||
set
|
||||
{
|
||||
_selectedProduct = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
// Commands
|
||||
public ICommand AddProductCommand { get; set; }
|
||||
@@ -63,7 +80,7 @@ namespace MVVM_DEMO.ViewModels
|
||||
Products.Add(new Product
|
||||
{
|
||||
ProductName = $"Product {Products.Count + 1}",
|
||||
Price = randomPrice
|
||||
ProductPrice = randomPrice
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
Margin="10"
|
||||
VerticalAlignment="Top"
|
||||
ItemsSource="{Binding Products}"
|
||||
SelectedItem="{Binding SelectedProduct, Mode=TwoWay}"
|
||||
DisplayMemberPath="ProductName" />
|
||||
<Button x:Name="btnAddProduct"
|
||||
Content="Add Product"
|
||||
@@ -34,12 +35,12 @@
|
||||
<TextBox x:Name="txtProductName"
|
||||
Width="200"
|
||||
Height="30"
|
||||
Text="{Binding productName}"
|
||||
Text="{Binding SelectedProduct.ProductName, UpdateSourceTrigger=PropertyChanged}"
|
||||
/>
|
||||
<TextBox x:Name="txtProductPrice"
|
||||
Width="200"
|
||||
Height="30"
|
||||
Text="{Binding productPrice}" />
|
||||
Text="{Binding SelectedProduct.ProductPrice, UpdateSourceTrigger=PropertyChanged}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
@@ -35,10 +35,11 @@ namespace MVVM_DEMO
|
||||
// display selected product details
|
||||
if (comboBox.SelectedItem != null && DataContext is MainViewModel viewModel)
|
||||
{
|
||||
viewModel.productName = ((Product)comboBox.SelectedItem).ProductName;
|
||||
viewModel.productPrice = (int)((Product)comboBox.SelectedItem).Price;
|
||||
viewModel.OnPropertyChanged("productName");
|
||||
viewModel.OnPropertyChanged("productPrice");
|
||||
/*viewModel.productName = ((Product)comboBox.SelectedItem).ProductName;
|
||||
viewModel.productPrice = (int)((Product)comboBox.SelectedItem).ProductPrice;
|
||||
viewModel.OnPropertyChanged(nameof(viewModel.productName));
|
||||
viewModel.OnPropertyChanged(nameof(viewModel.productPrice));*/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user