
<Window x:Class="Binding2.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">
<StackPanel Orientation="Vertical">
<StackPanel HorizontalAlignment="Left" Name="stackPanel1" VerticalAlignment="Top" Width="165" Orientation="Horizontal">
<TextBlock Height="20" Name="_sourceTextBlock" Text="Source" Width="67" />
<TextBox Height="20" Name="_sourceTextBox" Width="92" />
</StackPanel>
<StackPanel HorizontalAlignment="Left" Name="stackPanel2" VerticalAlignment="Top" Width="165" Orientation="Horizontal">
<TextBlock Height="20" Name="_destTextBlock" Text="Destination" Width="67" />
<TextBox Height="20" Name="_destTextBox" Width="92" />
</StackPanel>
</StackPanel>
</Window>
I have two text boxes. How can I program that the value in Destination text box is automatically modified based on the value in Source text box? For example, when the value in Source is “abc”, how can I make the value in Destination is automaticaly “x” + “abc” + “x”? Or, make destination the number 10*source.
ADDED
I also found a way to get the result when the source is more than one – Bind an element to two sources
That’s easy using MVVM :
Use that class as the
DataContextfor your view, and bind oneTextBoxtoSource(TwoWay), and the other toDestination(OneWay):Anyway, if you’re building a non-trivial WPF application, I strongly recommend moving to the MVVM pattern, in the long-term your app will be much easier to maintain.