Posts

Showing posts with the label icommand

To Load, Add, Update and Delete records from database using EntityFramework in WPF, MVVM

Image
In this Post, we'll walk you through creating a WPF application with CRUD (Create, Read, Update, Delete) and also we will learn how to implement  ICommand. Here i will perform CURD operations on Employee having the properties ID, Name, Age, Gender, and Address. Plus, we'll add buttons to perform these operations seamlessly. Let's get started! Step 1: Setting Up Your Project Open Visual Studio: Launch Visual Studio and create a new WPF project. <Window x:Class="CURD.Views.EmployeeDetails"         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:CURD.Views"         mc:Ignorable="d"         Title="EmployeeDetails"         xmlns:sys="

Step by step guide to implement the command in wpf

Image
To create the custom command we need to implement ICommand interface which is having two method called CanExecute and Execute and one EventHandler called CanExecuteChanged. CanExecute method is responsible to tell if commend will execute or not. Execute method perform the action. Step to create custom command: Implement the ICommand write a constructor which will take two parameters of type Action and Func respectively. if you want to trigger CanExecute on property change then add the method which should invoke CanExecuteChanged  EventHandler . Why Action? Action delegate is used for performing the action. As our actual implementation of  this Action will present in our ViewModel and we need to pass ViewModel method as a constructor parameter so that we can assign it in our CustomCommand and can invoke when require. Why Func? Func delegate is used when we want to pass some value and return some value. As our actual implementation of  this Func will present in our ViewModel and we ne