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