using System; using System.ComponentModel; using System.Diagnostics; using System.Windows; using System.Windows.Data; namespace BindingTest { public partial class MainWindow : Window, INotifyPropertyChanged { public MainWindow() { InitializeComponent(); DataContext = this; } string theText; public string TheText { get { return theText; } set { if (theText != value) { theText = value; OnPropertyChanged("TheText"); } } } public event PropertyChangedEventHandler PropertyChanged; void OnPropertyChanged(string s) { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(s)); } private string s = "String A"; private void SetTarget(object sender, RoutedEventArgs e) { TB.Text = s; s = s == "String A" ? "String B" : "String A"; } } public class TBConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value == null) return Binding.DoNothing; return ((string)value).ToUpper(); } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return ((String)value).ToLower(); } } }XAML:
<Window x:Class="BindingTest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" xmlns:local="clr-namespace:BindingTest"> <Window.Resources> <local:TBConverter x:Key="TBC" /> </Window.Resources> <StackPanel> <TextBox x:Name="TB" Height="31" HorizontalAlignment="Left" Margin="71,45,0,0" VerticalAlignment="Top" Width="148" Text="{Binding Path=TheText,Mode=TwoWay, Converter={StaticResource TBC}}"/> <TextBox x:Name="TB2" Height="31" HorizontalAlignment="Left" Margin="71,45,0,0" VerticalAlignment="Top" Width="148" Text="{Binding Path=TheText,Mode=TwoWay, Converter={StaticResource TBC}}"/> <Button Click="SetTarget">Set Target</Button> </StackPanel> </Window>The binding and converter still appear to be operating after 'TB.Text = s;' (you need to set focus to the TextBox and tab out to get the source updated or, better, just set the UpdateSourceTrigger to PropertyChanged)