Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all 18858 articles
Browse latest View live

How to feed a multi-column listbox from a DataTable?

$
0
0

I have a DataGrid that is being fed from a DataTable. The problem is that I need for the rows to wrap because the data being displayed is only a few number of narrow columns wide which results in the majority of the View being blank. The solution is to replace the DataGrid with a ListBox that displays items in a wrap panel resulting in a better utilization of the available screen. However, I'm not sure how to bind a DataGrid to the individual columns in this wrapping listbox.

That's the background. Now, given a theoretical situation where the DataTable has 3 columns and there ListBox.ItemTemplate defines 3 TextBlocks, how does one associate a particular TextBlock with a particular column in the DataTable row?


Richard Lewis Haggard


FBX 3D Scene in WPF App?

$
0
0

Hello, If I create a Winforms app in VS2013 then I can add a 3D graphics (fbx) scene no problem. What I want to do is put the scene into  a WPF Main Window (or an MDI parent-child). Can anyone tell me if this is possible, and if so the bet way? I have a 3D CAD model that I want to load as a resource. I also want to allow user input via a linked dialog and save a file of these settings.

Many thanks in advance for any help

Mick

Problem to Tab item

$
0
0
Hi,
Here is one xaml file
<Application x:Class="WpfBrowserApplication1.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="Page1.xaml"><Application.Resources><TabControl x:Key="tc" x:Shared="False"><TabItem Header="1"><TextBlock></TextBlock></TabItem><TabItem Header="2"><TextBlock></TextBlock></TabItem></TabControl></Application.Resources></Application>

Here is another xaml file

<Page x:Class="WpfBrowserApplication1.Page1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Page1"><Grid></Grid></Page>

how to run the relevant project to show Tab Item?

Many Thanks & Best Regards, Hua Min

Calculations delays slider value update.

$
0
0

Hello folks!

I've encountered a problem with performance in my WPF application.

I created a 2D model and added a couple of sliders like below.


The slider changes the value in the textbox by .1 as shown in the picture. It works perfect to me. Then I've done some function that gets the value from the textbox, performs some calculations (math intense calculations) and show result in another user control. It delays slider value update. How I can solve it? Any advice would be most welcome!

How to add a DataTemplate to a particular GridView Column cell in c#

$
0
0

Dear all,

I have a WPF application where I need , unfortunatly, to apply a particular DataTemplate to a GridView column cell.
I have try different things but the template did not apply at all, but data bind to the itemSource of the gridview are correctly displayed

The XAML layout of the list is as below :

<ListView
                    x:Name="lvParameterList"
                    ItemsSource="{Binding}"
                    ItemContainerStyle="{DynamicResource ListViewItemContainerStyle}"
                    BorderThickness="0"
                    SelectionChanged="lvParameterList_SelectionChanged" FontSize="14"><ListView.View><GridView
                            x:Name="gvParameterList"
                           ColumnHeaderContainerStyle="{DynamicResource GridViewColumnHeaderStyle}" /></ListView.View><ListView.Style><Style TargetType="{x:Type ListView}"><Style.Triggers><Trigger Property="DataContext" Value="{x:Null}"><Setter Property="Visibility" Value="{x:Static Visibility.Collapsed}"/></Trigger><!--<DataTrigger Binding="{Binding Path=Status}" Value="0"></DataTrigger>--></Style.Triggers></Style></ListView.Style></ListView>

The c# code where I am building dynamically the gridview column is as below :

gvParameterList.Columns.Clear(); foreach (DataColumn dataCol in dt.Columns) { //if (dataCol.ColumnName != "RecordNb" && dataCol.ColumnName != "PageCount" && dataCol.ColumnName != "Status") //change on 29/10/2015 to add status field if (dataCol.ColumnName != "RecordNb" && dataCol.ColumnName != "PageCount" ) { GridViewColumn gvCol = new GridViewColumn(); gvCol.DisplayMemberBinding = new Binding(dataCol.ColumnName) { Converter = new Maillefer.Nomos.Plateform.UI.Common.DateTimeConverterToCurrentCulture() }; gvCol.Header = T.Texts[rpt.ReportType.ToString() + "_" + dataCol.Caption]; if (dataCol.ColumnName=="Status" && dataCol.DataType==typeof(System.Int16)) { DataTemplate cell = new DataTemplate(); Binding bind = new Binding(dataCol.ColumnName); FrameworkElementFactory factory = new FrameworkElementFactory(typeof(TextBlock)); //factory.SetBinding(TextBlock.TextProperty, bind);//the second parameter should be bind factory.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);//set the text align to right factory.SetValue(TextBlock.BackgroundProperty, System.Windows.Media.Brushes.Blue); factory.SetValue(TextBlock.ForegroundProperty, new SolidColorBrush(Colors.Yellow)); cell.VisualTree = factory; gvCol.CellTemplate = cell; } gvParameterList.Columns.Add(gvCol); } }

lvParameterList.DataContext = dt;

What I am basically doing here is that if the column name is "Status", its binding value is either 0 or 1.
At the end If it is 0 I need to set the color of background as green and if 1 as red, but for simplification I simply add a textbox to this cell and chge some property to see if it applies.

But the datatemplate is not apply at all.

 The context for the item source is defined by the last line

Any idea why the datatemplate is not apply to the Status column cell ?

Regards

Placing .fbx 3D Scenes in XAML

$
0
0

I see no way to insert my .fbx 3D Scene into my XAML Window.  I try dragging it in, and it gives the "No" symbol.

Do I need to do something with the scene?  Do I need to create a Viewport3D?

Help

$
0
0

When I query values match when time is stretched,
How can I shorten this period?

I wrote the code are;

 public int ParcelFilter(System.Windows.Controls.TextBox txtada, System.Windows.Controls.TextBox txtparsel, System.Windows.Controls.TextBox txthektar, System.Windows.Controls.TextBox txtmetre, System.Windows.Controls.TextBox txtdesimetre)
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();
            string AdaParsel = txtada.Text + "/" + txtparsel.Text;
            for (int j = 0; j < _NCSObj.NumObject() - 1; j++)
            {
                var ParcelFilter = _NCSObj.GetObject(j);
                if (ParcelFilter.Tag == NetGISObjectTag.opline)
                {
                    var obje = new StringComparer();
                    int filter = (int)obje.Compare(AdaParsel, ParcelFilter.pname);
                    if (filter == 0)
                    {
                        var _GetPlineExt = _NCSObj.GetPlineExt(ParcelFilter);
                        _GetPlineExt.CalcLimits();
                        _GetPlineExt.Limits.cll.y = _GetPlineExt.Limits.cll.y - 40;
                        _GetPlineExt.Limits.cll.x = _GetPlineExt.Limits.cll.x - 40;
                        _GetPlineExt.Limits.cur.y = _GetPlineExt.Limits.cur.y + 40;
                        _GetPlineExt.Limits.cur.x = _GetPlineExt.Limits.cur.x + 40;
                        _NCSObj.SetCurrentWindow(_GetPlineExt.Limits, true);
                        _NCSObj.DrawObject(ParcelFilter, NetGISColors.Red);
                        double dArea = Math.Round(_GetPlineExt.Area, 2);
                        txthektar.Text = string.Format("{0}", Hectares(dArea));
                        txtmetre.Text = string.Format("{0:000#}", Meters(dArea));
                        txtdesimetre.Text = string.Format("{0:0#}", Decimetre(dArea));
                        return filter;
                    }
                }
                ParcelFilter = null;
            }
            sw.Stop();
            MessageBox.Show(string.Format("Time elapsed : {0}  - [{1}]", sw.ElapsedMilliseconds, sw.ElapsedTicks));
            txthektar.Text = "0";
            txtmetre.Text = "0000";
            txtdesimetre.Text = "00";
           return 0;
        }
        public int Hectares(double area)
        {
            int hectares = (int)(decimal)area / 10000;
            return hectares;
        }
        public int Meters(double area)
        {
            int meters = (int)(decimal)area % 10000;
            return meters;
        }
        public int Decimetre(double area)
        {
            int decimetre = (int)(((decimal)area % 1) * 100);
            return decimetre;
        }

and

 public class StringComparer : IComparer
    {
        public int Compare(object adaparsel, object filteradaparsel)
        {
            string s1 = adaparsel as string;
            string s2 = filteradaparsel as string;
            return -String.Compare(s1, s2);
        }
    }


Thanks;



Modular application used shared resources

$
0
0
Hi community,

I develop a modular application with WPF. I want to share Styles and Templates in a ResourceDictionary.

I have some projects like this:

 - MainApplication
 - ModuleA
 - ModuleB
 - ModuleC
 - SharedResources
 
Each project reference the SharedResources project. The MainApplication has the App.xaml file with a ResourceDictionary, which is defined in the SharedResources project. The projects ModuleA, ModuleB and ModuleC don't reference the MainApplication.
ModuleA has a view of type UserControl. The UserControl has a Style Property like this:

<UserControl x:Class="ModuleA" ... Style="{StaticResource HeaderedPage}">

If I start the application everything works fine, but the Visual Studio Designer cannot load the style. What is the best practice to solve the problem?

Refresh the WPF Main Window

$
0
0

I need some help with a concept that I would like to add to an app that I am working on.  It is an existing app, who's start up has a lot of parts.  I would like to have the ability to refresh the application data, but basically close the main window and reopen it to reinitialize it.  

Could someone provide some insight on how this could be down without the application closing before the main window opens back up?

Thank you,

WPF c# Command="EditingCommands.ToggleSuperscript" does not work

$
0
0
<RibbonRadioButton Command="EditingCommands.ToggleSuperscript"  SmallImageSource="Resources\I_35x35.png" Label="" KeyTip="S" VerticalAlignment="bottom" Margin="35,-62,-17,5" />

Thank You

Mike

WPF c# I i place my cursor in a richtextbox next to a letter fontsize 14 I wanted some code to change the combobox to value 14

$
0
0
WPF c# I i place my cursor in a richtextbox next to a letter fontsize 14 I wanted some code to change the combobox to value 14

Matrix3D in DirectX to place 3D Objects in XAML

$
0
0

I read this post

https://social.msdn.microsoft.com/Forums/windowsapps/en-US/1194a6ad-e1fd-4ecd-948f-6ef25037b8c6/3d-animation-in-xaml?forum=winappswithcsharp

I don't seem to be able to pull up <Matrix3D> in my XAML, I'm using a DirextX App and XAML.

I have been doing everything I can think of to place my 3D Scene (.fbx) into my XAML.

TabControl - can't remove right and bottom border?

$
0
0

It seems the WPF TabControl has a "2nd" border (right and bottom) that can't be removed in any way.

 

Setting the BorderThickness=0,0,0,0 still leaves two lines on the right and bottom of the control.  Can these be removed?  I can't seem to find any way to access them, remove them, or even change their color.

 

 

Get object after add ObservableCollection

$
0
0
Hi guys! How can i Get object after add ObservableCollection? is it possible(add new object in datagrid wpf)

NullReferanceException was unhandled by usercode

$
0
0

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


NullReferanceException was unhandled by usercode

$
0
0

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

NullReferanceException was unhandled by usercode

$
0
0

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

NullReferanceException was unhandled by usercode

$
0
0

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

Navigation Service on Another Frame

$
0
0

I currently have a program that has a Window containing two frames, one at the top of the screen, similar to a navigation panel where the user can click on different buttons to navigate to areas of the program, which are loaded into the frame below.

The top frame permanently stays the same, i.e. there are buttons saying QuestionsTags and Users for example that do not change. When the user clicks the Questions button they should be taken to the relevant area of the program but within the frame below.

The problem with this is that because they are within the top frame the NavigationService loads the relevant page in the frame at the top, not in the main frame in the centre of the screen.

Is there a way that a button clicked within one frame can cause a different frame to load a different page through the NavigationService? Here is a paint example;

enter image description here

What I originally planned on doing is to have the top frame not in a frame, but in the window itself. However because the window does not inherit from the page, I couldn't use the NavigationService.

Readonly PropertyUpdate

$
0
0

Hello please tell me how update readonlyproperty? read about dependency but i understande how it use

   public double Total
        {
            get { return (double) ((Count*Ingredient.Price)/100); }

        }

Viewing all 18858 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>