Karthikeyan K

Karthikeyan K

  • NA
  • 5.5k
  • 1.4m

TextBox Binding in XAML

Sep 1 2016 3:53 AM

Hi ,

Anyone please help me

My textbox will show listview seleted item 
 
<TextBox Name="txt1" HorizontalAlignment="Left" Height="23" Margin="46,90,0,0" TextWrapping="Wrap" Text="{Binding ElementName=_PList,Path=SelectedItem.FirstName,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" Width="120" Grid.Column="1" Grid.RowSpan="2"/>
 
 if I modify like this I can add new item
<TextBox Name="txt1" HorizontalAlignment="Left" Height="23" Margin="46,90,0,0" TextWrapping="Wrap" Text="{Binding Path=Firstname,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" Width="120" Grid.Column="1" Grid.RowSpan="2"/>
 
my question is how to achieve both scenario in binding way
 
I want to connect First property to Firstname,Firstname is model class property
 
I have added below logic in my viewmodel 

public string First

{

get { return _First; }

set { SetProperty(ref this._First, value); }

}

 

public void AddPerson()

{

this.PersonMaster.Add(new Person()

{

FirstName=this.First             

}

);

}

 
 
 
 

Answers (3)