Hello everyone
I am not expert in neither binding nor WPF.
I have problem in this very simple program.
I have 3 text boxes:
1- First Name
2- Surname
3- Full Name
When I change First Name or Surname, Full Name textbox does not update
this is my program. please have a look at it:
WPF:
<Window x:Class="myTutorial_WPF_Binding_Example.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:src="clr-namespace:WPF_Binding_Example"
Title="MainWindow" Height="385" Width="563">
<Window.Resources>
<src:Person x:Key="myDataSourceObject" PersonFirstName="AAA" PersonSurName="Davis"/>
</Window.Resources>
<Grid>
<TextBlock Margin="10,16,0,0" Text="First Name: " VerticalAlignment="Top" HorizontalAlignment="Left" />
<TextBlock Margin="18,46,0,0" Text="SurName: " VerticalAlignment="Top" HorizontalAlignment="Left" />
<TextBlock Margin="14,80,0,0" Text="Full Name: " VerticalAlignment="Top" MaxWidth="Infinity" HorizontalAlignment="Left" />
<TextBox Margin="79,13,79,0"
Text="{Binding Source={StaticResource myDataSourceObject}, Path=PersonFirstName}"
VerticalAlignment="Top" />
<TextBox Margin="79,43,79,0"
Text="{Binding Source={StaticResource myDataSourceObject}, Path=PersonSurName}"
VerticalAlignment="Top" />
<TextBox Margin="79,77,79,0"
Text="{Binding Source={StaticResource myDataSourceObject}, Path=PersonFullName}"
VerticalAlignment="Top" />
</Grid>
</Window>
and this is my class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WPF_Binding_Example
{
public class Person
{
private string _personFirstName;
public string PersonFirstName
{
set
{
_personFirstName = value;
PersonFullName = PersonFirstName + " " + PersonSurName;
}
get { return _personFirstName; }
}
private string _personSurName;
public string PersonSurName
{
set
{
_personSurName = value;
PersonFullName = PersonFirstName + " " + PersonSurName;
}
get { return _personSurName; }
}
public string PersonFullName { set; get; }
}
}