XAML text field updated on TextChanged event

I use XAML and data binding (MVVM). I need to update a shortcut when my user writes a new text character in a TextBox.

Xaml

    <Window x:Class="WpfApplication1.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">
    <Grid>
        <TextBox Height="23" HorizontalAlignment="Left" Margin="12,12,0,0" Name="textBox1" VerticalAlignment="Top" Width="463" Text="{Binding OriginalText}"/>
        <Label Height="28" HorizontalAlignment="Left" Margin="12,41,0,0" Name="label1" VerticalAlignment="Top" Width="463" Content="{Binding ModifiedText}"/>
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="400,276,0,0" Name="button1" VerticalAlignment="Top" Width="75" />
    </Grid>
</Window>

ViewModel

    class MainViewModel : NotifyPropertyChangedBase
    {
        private string _originalText = string.Empty;
        public string OriginalText
        {
            get { return _originalText; }
            set
            {
                _originalText = value;
                NotifyPropertyChanged("OriginalText");
                NotifyPropertyChanged("ModifiedText");
            }
        }

        public string ModifiedText
        {
            get { return _originalText.ToUpper(); }
        }
    }

I added a button in XAML. The button does nothing, but helps me lose the focus of my text box. When I lose focus, the anchor is updated and the top text appears on my label. But data binding is only updated when the text loses focus. The TextChanged event does not update the binding. I would like to force update the TextChanged event. How can i do this? Which component should I use?

+5
source share
1 answer
 <TextBox Name="textBox1"
      Height="23" Width="463"
      HorizontalAlignment="Left" 
      Margin="12,12,0,0"   
      VerticalAlignment="Top"
      Text="{Binding OriginalText, UpdateSourceTrigger=PropertyChanged}" /> 

MSDN . TextBox :

TextBox.Text UpdateSourceTrigger. LostFocus. , TextBox TextBox.Text, , TextBox , TextBox ( , TextBox).

, , UpdateSourceTrigger PropertyChanged. Text TextBox, TextBlock . UpdateSourceTrigger TextBox PropertyChanged.

+11
source

All Articles