Hi friends today we will discuss Add,Change,Delete functionality in WPF.
Introduction
Hi friends today we will discuss Add,Change,Delete functionality in WPF

- Once open the Visual Studio click on File Click on the Project .
- As you can see there are many application(s) from them Select WPF application
- At name rename it as per your requirement .
- Right click on the project and click on add from there click on window for adding a new window to the project
- Rename the window as per your requirement
- Drag a Dockpanel from tools .
- Drag a three Button and rename it as showed above .
- Now its time to enable the functionality using the below code we can achieve it.
<Window x:Class="DataBindingExamples.Window3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window3" Height="300" Width="300">
<DockPanel Margin="10">
<StackPanel DockPanel.Dock="Right" Margin="10,0,0,0">
<Button Name="btnAddUser" Click="btnAddUser_Click">Add user</Button>
<Button Name="btnChangeUser" Click="btnChangeUser_Click" Margin="0,5">Change user
</Button>
<Button Name="btnDeleteUser" Click="btnDeleteUser_Click">Delete user</Button>
</StackPanel>
<ListBox Name="lbUsers" DisplayMemberPath="Name"></ListBox>
</DockPanel>
</Window>
Window3.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Collections.ObjectModel;
namespace DataBindingExamples
{
/// <summary>
/// Interaction logic for Window3.xaml
/// </summary>
public partial class Window3 : Window
{
private ObservableCollection<User> users = new ObservableCollection<User>();
public Window3()
{
InitializeComponent();
users.Add(new User() { Name = "Jojo" });
users.Add(new User() { Name = "Popat Lal" });
users.Add(new User() { Name = "Santa Singh" });
users.Add(new User() { Name = "Banta Singh" });
lbUsers.ItemsSource = users;
}
private void btnAddUser_Click(object sender, RoutedEventArgs e)
{
users.Add(new User() { Name = "Steve" });
}
private void btnChangeUser_Click(object sender, RoutedEventArgs e)
{
if (lbUsers.SelectedItem != null)
(lbUsers.SelectedItem as User).Name = "Smith";
}
private void btnDeleteUser_Click(object sender, RoutedEventArgs e)
{
if (lbUsers.SelectedItem != null)
users.Remove(lbUsers.SelectedItem as User);
}
}
public class User:INotifyPropertyChanged
{
private String _name;
public String Name
{
get
{
return this._name;
}
set
{
if (this._name != value)
{
this._name = value;
this.NotifyPropertyChanged("Name");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(String propname)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propname));
}
}
}
}

ADD
Change
Delete
Conclusion
In this article we have seen how to add user,Change user,Delete a user Using WPF.

About the Author