xaml:
<Grid x:Name="grid_AdminData" Margin="1,4,1,0">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Label Content="AdminID :" HorizontalAlignment="Left" VerticalAlignment="Top" Height="18" Padding="0,0,5,5" Foreground="White"
FontStyle="Normal" FontWeight="Bold" FontFamily="Times New Roman" Width="82" FontSize="14" Margin="1,0,0,0"/>
<Label Content="City :" Target="{Binding ElementName=txtCity}" HorizontalAlignment="Left" VerticalAlignment="Top" Height="18"
Padding="0,0,5,0" Foreground="White" FontStyle="Normal" FontWeight="Bold" FontFamily="Times New Roman" Width="82" FontSize="14" Grid.Column="1" Grid.Row="2" Margin="0,1,0,0"/>
<Label Content="Full Name :" Target="{Binding ElementName=txtFullName}" HorizontalAlignment="Left" VerticalAlignment="Top"
Height="18" Padding="0,0,5,5" Foreground="White" FontStyle="Normal" FontWeight="Bold" FontFamily="Times New Roman" Width="82" FontSize="14" Grid.Column="1" Margin="0"/>
<Label Content="Address :" HorizontalAlignment="Left" VerticalAlignment="Top" Height="18" Padding="0,0,5,5" Foreground="White"
FontStyle="Normal" FontWeight="Bold" FontFamily="Times New Roman" Width="71" Margin="1,1,0,0" Grid.Row="2" FontSize="14"/>
<Label Content="State :" HorizontalAlignment="Left" VerticalAlignment="Top" Height="18" Padding="0,0,5,5" Foreground="White"
FontStyle="Normal" FontWeight="Bold" FontFamily="Times New Roman" Width="82" FontSize="14" Grid.Column="1" Grid.Row="4" Margin="2,1,0,0"/>
<Label Content="Postal Code :" HorizontalAlignment="Left" VerticalAlignment="Top" Height="18" Padding="0,0,5,5" Foreground="White"
FontStyle="Normal" FontWeight="Bold" FontFamily="Times New Roman" Width="93" FontSize="14" Grid.Column="1" Grid.Row="6" Margin="0,1,0,0"/>
<Label Content="Gender :" HorizontalAlignment="Left" VerticalAlignment="Top" Height="18" Padding="0,0,5,5" Foreground="White"
FontStyle="Normal" FontWeight="Bold" FontFamily="Times New Roman" Width="101" FontSize="14" Grid.Column="2" Margin="1,0,0,0"/>
<Label Content="E-Mail ID :" HorizontalAlignment="Left" VerticalAlignment="Top" Height="18" Padding="0,0,5,5" Foreground="White"
FontStyle="Normal" FontWeight="Bold" FontFamily="Times New Roman" Width="82" FontSize="14" Grid.Column="2" Grid.Row="2" Margin="1,1,0,0"/>
<Label Content="Designation :" HorizontalAlignment="Left" VerticalAlignment="Top" Height="18" Padding="0,0,5,2" Foreground="White"
FontStyle="Normal" FontWeight="Bold" FontFamily="Times New Roman" Width="101" FontSize="14" Grid.Column="2" Grid.Row="4" Margin="1,1,0,0"/>
<Label Content="Employee Photo :" HorizontalAlignment="Left" VerticalAlignment="Top" Height="18" Padding="0,0,5,2"
Foreground="White" FontStyle="Normal" FontWeight="Bold" FontFamily="Times New Roman" Width="118" FontSize="14" Grid.Column="3" Grid.Row="6" Margin="1,1,0,0"/>
<Label Content="UserName:" HorizontalAlignment="Left" VerticalAlignment="Top" Height="18" Padding="0,0,5,2" Foreground="White"
FontStyle="Normal" FontWeight="Bold" FontFamily="Times New Roman" Width="101" FontSize="14" Grid.Column="3" Margin="1,0,0,0"/>
<Label Content="Password :" HorizontalAlignment="Left" VerticalAlignment="Top" Height="18" Padding="0,0,5,2" Foreground="White"
FontStyle="Normal" FontWeight="Bold" FontFamily="Times New Roman" Width="101" FontSize="14" Grid.Column="3" Grid.Row="2" Margin="1,1,0,0"/>
<Label Content="ConfirmPassword :" HorizontalAlignment="Left" VerticalAlignment="Top" Height="18" Padding="0,0,5,2"
Foreground="White" FontStyle="Normal" FontWeight="Bold" FontFamily="Times New Roman" Width="129" FontSize="14" Grid.Column="3" Grid.Row="4" Margin="1,1,0,0"/>
<TextBox x:Name="txtID" Grid.Row="1" Margin="0,0,45,0" Padding="0" FontStyle="Normal" FontSize="14" FontFamily="Times
New Roman" FontWeight="Normal" IsReadOnly="True"/>
<TextBox x:Name="txtFullName" Style="{StaticResource VallidationTemplate}" Validation.Error="Validation_Error"
Text="{Binding UpdateSourceTrigger=LostFocus, Path=FullName,ValidatesOnExceptions=True,
ValidatesOnDataErrors=true, NotifyOnValidationError=true}" Grid.Row="1" Margin="0,1,40,0" Grid.Column="1" FontFamily="Times
New Roman" FontSize="14" FontStyle="Normal" FontWeight="Normal" Height="19"/>
<TextBox x:Name="txtUserName" Grid.Row="1" Margin="0,0,40,0" Grid.Column="3" FontFamily="Times New Roman" FontSize="14"
FontStyle="Normal" FontWeight="Normal" IsReadOnly="True"/>
<TextBox x:Name="txtDesignation" Grid.Row="5" Margin="0,0,41,0" Grid.Column="2" FontFamily="Times New Roman" FontSize="14"
FontStyle="Normal" FontWeight="Normal"/>
<TextBox x:Name="txtEmpPhoto" Grid.Row="7" Margin="0,0,100,0" Grid.Column="3" FontFamily="Times New Roman" FontSize="14"
FontStyle="Normal" FontWeight="Normal" IsReadOnly="True"/>
<RadioButton x:Name="rbtMale" Content="Male" Grid.Column="2" Grid.Row="1" FontFamily="Times New Roman" FontSize="14"
FontStyle="Normal" Margin="0,0,113,0" Foreground="White"/>
<RadioButton x:Name="rbtFemale" FontStyle="Normal" FontFamily="Times New Roman" FontSize="14" Grid.Column="2" Margin="63,0,41,0"
Grid.Row="1" Content="Female" Foreground="White"/>
<TextBox x:Name="txtCity" Style="{StaticResource VallidationTemplate}" Validation.Error="Validation_Error"
Text="{Binding UpdateSourceTrigger=LostFocus, Path=City,ValidatesOnExceptions=True,
ValidatesOnDataErrors=true, NotifyOnValidationError=true}" Grid.Row="3" Margin="0,1,40,0" Grid.Column="1" FontFamily="Times
New Roman" FontSize="14" FontStyle="Normal" FontWeight="Normal" Height="19"/>
<TextBox x:Name="txtState" Style="{StaticResource VallidationTemplate}" Validation.Error="Validation_Error"
Text="{Binding UpdateSourceTrigger=LostFocus, Path=State,ValidatesOnExceptions=True,
ValidatesOnDataErrors=true, NotifyOnValidationError=true}" Grid.Row="5" Margin="0,1,40,18" Grid.Column="1"
FontFamily="Times New Roman" FontSize="14" FontStyle="Normal" FontWeight="Normal" Height="20" Grid.RowSpan="2"/>
<TextBox x:Name="txtPostal" Style="{StaticResource VallidationTemplate}" Validation.Error="Validation_Error"
Text="{Binding UpdateSourceTrigger=LostFocus, Path=PostalCode,ValidatesOnExceptions=True,
ValidatesOnDataErrors=true, NotifyOnValidationError=true}" Grid.Row="7" Margin="0,0,40,0" Grid.Column="1" FontFamily="Times
New Roman" FontSize="14" FontStyle="Normal" FontWeight="Normal"/>
<TextBox x:Name="txtAddress" Style="{StaticResource VallidationTemplate}" Validation.Error="Validation_Error"
Text="{Binding UpdateSourceTrigger=LostFocus, Path=Address,ValidatesOnExceptions=True,
ValidatesOnDataErrors=true, NotifyOnValidationError=true}" Grid.Row="3" Margin="0,1,45,1" Grid.RowSpan="5"
FontFamily="Times New Roman" FontSize="14" FontStyle="Normal" FontWeight="Normal" Height="97"/>
<TextBox x:Name="txtEMail" Grid.Row="3" Margin="0,0,41,0" Grid.Column="2" FontSize="14" FontFamily="Times New
Roman" FontStyle="Normal" FontWeight="Normal"/>
<Label Content="Mobile :" HorizontalAlignment="Left" VerticalAlignment="Top" Height="18" Padding="0,0,5,2" Foreground="White"
FontStyle="Normal" FontWeight="Bold" FontFamily="Times New Roman" Width="101" FontSize="14" Grid.Column="2" Grid.Row="6" Margin="1,1,0,0"/>
<TextBox x:Name="txtMobile" Grid.Row="7" Margin="0,0,41,0" Grid.Column="2" FontFamily="Times New Roman" FontSize="14"
FontStyle="Normal" FontWeight="Normal"/>
<PasswordBox HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="3" Grid.Row="3" Width="133" Height="20"/>
<PasswordBox x:Name="txt" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="3" Grid.Row="5" Width="133"
Height="20" FontWeight="Normal" FontFamily="Times New Roman" FontSize="14"/>
<Button x:Name="btnBrowse" Style="{StaticResource BrowseButtonStyleTemplate}" Content="Browse" HorizontalAlignment="Left" VerticalAlignment="Top"
Width="58" Grid.Column="3" Grid.Row="7" Margin="114,0,0,0" FontStyle="Normal" Padding="1,0,1,1" Click="btnBrowse_Click" FontFamily="Times New Roman" Height="20"/>
</Grid>
Cs :
namespace ITA
{
/// <summary>
/// Interaction logic for AdminMaster.xaml
/// </summary>
public partial class AdminMaster : Window
{
private int _errors = 0;
private Person _Person = new Person();
public AdminMaster()
{
InitializeComponent();
grid_AdminData.DataContext = _Person;
}
public string conn_String = "Data Source=Dell;Initial Catalog=ITA;User ID=sa;Password=12345";
private void btnBrowse_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
Nullable<bool> dlgRes = ofd.ShowDialog();
if (dlgRes == true)
{
txtEmpPhoto.Text = ofd.FileName;
}
}
private void Validation_Error(object sender, ValidationErrorEventArgs e)
{
if (e.Action == ValidationErrorEventAction.Added)
_errors++;
else
_errors--;
}
}
}
Viewmodel Class : person
namespace ITA
{
public class Person : IDataErrorInfo, INotifyPropertyChanged
{
public Person()
{
}
private string F_Name = "";
public string FullName
{
get
{
return F_Name;
}
set
{
if (F_Name != value)
{
F_Name = value;
OnPropertyChanged("FullName");
}
}
}
private string _City = "";
public string City
{
get
{
return _City;
}
set
{
if (_City != value)
{
_City = value;
OnPropertyChanged("City");
}
}
}
private string _State = "";
public string State
{
get
{
return _State;
}
set
{
if (_State != value)
{
_State = value;
OnPropertyChanged("State");
}
}
}
private string P_Code;
public string PostalCode
{
get
{
return P_Code;
}
set
{
if (P_Code != value)
{
P_Code = value;
OnPropertyChanged("PostalCode");
}
}
}
private string _Address;
public string Address
{
get
{
return _Address;
}
set
{
if (_Address != value)
{
_Address = value;
OnPropertyChanged("Address");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public string Error
{
get { throw new NotImplementedException(); }
}
public string this[string columnName]
{
get
{
string result = "";
//string charVal = @"^[a-zA-Z]*$";
string txtVal = @"^[a-zA-Z]*\s[a-zA-Z]*\s[a-zA-Z]*\s$";
string numVal = @"[0-9]";
string ScharVal = @"[!|""|_|@|#|\$|%|\?|\>|\<|\*|\{|\}|\]|\[|\:|\;|\'|\/|\.|\,|\+|\=|\(|\)|\-]";
string mailVal = @"^((([\w]+\.[\w]+)+)|([\w]+))@(([\w]+\.)+)([A-Za-z]{1,3})$";
if (FullName.Length != 0 && !Regex.IsMatch(FullName, txtVal))
{
result = "Enter Full Name like\n LastName - FirstName - MiddleName ";
}
if (Regex.IsMatch(FullName, numVal) || Regex.IsMatch(FullName, ScharVal))
{
result = "Enter Proper Full Name";
}
if (Regex.IsMatch(City, numVal) || Regex.IsMatch(City, ScharVal))
{
result = "Enter Proper City";
}
if (Regex.IsMatch(State, numVal) || Regex.IsMatch(State, ScharVal))
{
result = "Enter proper State";
}
if (Regex.IsMatch(PostalCode, charVal) || Regex.IsMatch(PostalCode, ScharVal))
{
result = "Enter Proper PostalCode";
}
if (Address.Length != 0 && Address.Length < 1 || Address.Length > 50) // here i got this error of null referance exception
{
result = "Enter maximium 50 words";
}
return result;
}
}
}
}
how can i solve this error?? pls help me