Posts

Showing posts with the label MVVM

Donate

How To Apply Checkbox Check All To WPF DataGrid Using MVVM Pattern In VB.NET

Image
Good day Gents! In this post, I will demonstrate the VB.NET version on how to create a WPF DataGrid application that has a check all checkbox behavior for selecting all rows using the MVVM Pattern. First is we need to create a .NET WPF Visual Basic project that targets the .NET framework with a project structure similar to the screenshot below. App.config Update your App.config's connection string with your local database connection. <configuration> <startup> <supportedRuntime version= "v4.0" sku= ".NETFramework,Version=v4.5.2" /> </startup> <connectionStrings> <add name= "products" connectionString= "data source=.;Initial Catalog=TestDatabase;Trusted_Connection=True;" providerName= "System.Data.SqlClient" /> </connectionStrings> </configuration> DBUtil.vb The DBUtil class will retrieve records from the database and u

How To Apply Checkbox Check All To WPF DataGrid Using MVVM Pattern

Image
Good day Gents! In this post, I will demonstrate on how to create a WPF DataGrid application that has a check all checkbox behavior for selecting all rows using the MVVM Pattern. First is we need to create a .NET Core WPF project that targets the .NET 7 framework with a project structure similar to the screenshot below. App.config Update your App.config's connection string with your local database connection. <configuration> <connectionStrings> <add name= "products" connectionString= "data source=.;Initial Catalog=TestDatabase;Integrated Security=true;" providerName= "System.Data.SqlClient" /> </connectionStrings> </configuration> DBUtil.cs The DBUtil class will retrieve records from the database and update the discontinued field of a particular product. public static class DBUtil { public static DataTable GetProduct() { DataSet ds = new DataSet(); string q

How To Close A Window Via Click Command Using MVVM In WPF

Image
Good day! Here's a simple WPF tutorial on how to close a window in WPF thru button click which applies the MVVM pattern. For simplicity sake, I'll demonstrate by using Menu item with a command to close the window. Start by creating a WPF project that target's the latest framework and add classes for DelegateCommand, MainViewModel and ViewModelBase inside a ViewModels folder. See below project setup. Add the code for ViewModelBase class that implements the INotifyPropertyChanged interface. public class clsViewModelBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged( string propertyName) { if (PropertyChanged != null ) PropertyChanged( this , new PropertyChangedEventArgs(propertyName)); } } Next is to add the functionality of the DelegateCommand class that implements the ICommand interface. This class handles the Commands bound to the WPF controls pu

WPF MVVM - How To Pass ViewModel Or Element As ConverterParameter Value In XAML Code

Image
Good evening! In this post, I will demonstrate on how to pass a view model or an element as ConverterParameter value in XAML. This methodology is widely used by developers if you need to retrieve certain values or properties from a view model object or element. To send the view model data context as ConverterParameter value, reference the view model class in the data context node of your form or user control. <UserControl d:DesignHeight= "450" d:DesignWidth= "800" > <UserControl.DataContext> <localmain:ConfigurationResourceManagerViewModel x:Name= "vmResourceManager" /> </UserControl.DataContext> </UserControl> In your element as to where the ConverterParameter is, set it's value with the view model name. In the example snippet below, the ConverterParameter is used in the ComboBox SelectedItem property with a reference to the view model object. <DataGridTemplateColumn Header= "Resource

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And VB.NET

Image
Good day guys! Here's the VB.NET version of this article WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET which is a CRUD (Create,Update and Delete) application using the DataGrid control, ADO.NET Entity Framework 6.x and Model–View–Viewmodel(MVVM) architectural pattern. The project structure and the logic were derived from that article except that this application incorporates Visual Basic.NET/VB.NET as the programming language. I. Project Setup 1. Create a table in your database called Students using the script from this post WPF CRUD With DataGrid, Entity Framework And C#.NET . 2. Create a WPF Project and add four folders called DataAccess, Model, View and ViewModel. The project structure may resemble with the screenshot provided below. II. Coding The Model and Repository Class 1. Inside the Model folder, add an ADO.NET Entity Data Model object that connects to the Students table in your database. On my part, I named it StudentModel . 2. Fo

Donate