Posts

Showing posts with the label icommand

What is XAML in WPF? Explained with Simple Examples

Image
In this article, we’ll dive into one of the core building blocks of WPF — XAML. We’ll explore how it works and why it plays such an important role in building modern desktop applications. What is XAML? XAML stands for eXtensible Application Markup Language. It’s a markup language used to design the user interface in WPF applications. XAML allows developers and designers to work separately, making the code cleaner and easier to manage. Think of it as HTML for WPF apps. XAML Syntax XAML uses XML-style syntax. Every UI element is an XML tag. Attributes define properties like height, width, and content. You can also nest elements inside others to create more complex layouts. For example, placing a TextBlock inside a Grid layout. <Grid>     <TextBlock Text="Hello, WPF World!"                 Width="200"                 Height="50"              ...

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"       ...

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 ...