If I got this correctly and you don't necessarily need to edit the phone number in the main TextBox, you can use multibinding to accomplish this. Here is an example:
<DataTemplate x:Key="PhoneNumberTemplate">
<StackPanel Orientation="Horizontal">
<TextBox Name="tbPN1" />
<TextBox Name="tbPN2" />
<TextBox Name="tbPN3" />
<TextBox Name="tbPN4" />
<TextBox IsReadOnly="True">
<TextBox.Text>
<MultiBinding StringFormat="{}+{0} ({1}) {2} - {3}">
<Binding Path="Text" ElementName="tbPN1" UpdateSourceTrigger="PropertyChanged" />
<Binding Path="Text" ElementName="tbPN2" UpdateSourceTrigger="PropertyChanged" />
<Binding Path="Text" ElementName="tbPN3" UpdateSourceTrigger="PropertyChanged" />
<Binding Path="Text" ElementName="tbPN4" UpdateSourceTrigger="PropertyChanged" />
</MultiBinding>
</TextBox.Text>
</TextBox>
</StackPanel>
</DataTemplate>
This will update the main TextBox every time a key is pressed inside one of the other 4 TextBoxes
Update:
In order to 'update' the data source, I would do the following:
Have the PhoneNumber class implement INotifyPropertyChanged like this:
public class PhoneNumber : INotifyPropertyChanged {
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName) {
var handler = PropertyChanged;
if (handler != null) {
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
private string m_CountryCode;
public string CountryCode {
get { return m_CountryCode; }
set {
m_CountryCode = value;
ComputeFullNumber();
OnPropertyChanged("CountryCode");
}
}
private string m_AreaCode;
public string AreaCode {
get { return m_AreaCode; }
set {
m_AreaCode = value;
ComputeFullNumber();
OnPropertyChanged("AreaCode");
}
}
private string m_Number;
public string Number {
get { return m_Number; }
set {
m_Number = value;
ComputeFullNumber();
OnPropertyChanged("Number");
}
}
private string m_Suffix;
public string Suffix {
get { return m_Suffix; }
set {
m_Suffix = value;
ComputeFullNumber();
OnPropertyChanged("Suffix");
}
}
public string FullNumber { get; private set; }
private void ComputeFullNumber() {
FullNumber = string.Format("+{0} ({1}) {2} - {3}", m_CountryCode, m_AreaCode, m_Number, m_Suffix);
OnPropertyChanged("FullNumber");
}
}
Then your DataTemplate becomes:
<DataTemplate x:Key="PhoneNumberTemplate">
<StackPanel Orientation="Horizontal">
<TextBox Text="{Binding Path=CountryCode, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Text="{Binding Path=AreaCode, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Text="{Binding Path=Number, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Text="{Binding Path=Suffix, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Text="{Binding Path=FullNumber, Mode=OneWay}" IsReadOnly="True" />
</StackPanel>
</DataTemplate>