-1

I have a C# WPF question. I need to set a trigger event to examine that if the content in a textbox has been changed. No matter a user adds or deletes any character in the textbox, I can get this as a trigger event. How to do this? Thanks.

J.Jiang
  • 11
  • 3
  • @ASh, OP say "trigger event" not *binding*, nor *setter*. – Sinatr Aug 29 '17 at 08:28
  • 1
    @Sinatr, my telepathic-debug co-processor is malfunctioning and may return false-positives. Glad that your is ok and and you have enough energy to write code on demand – ASh Aug 29 '17 at 08:32

2 Answers2

0

I've done something similar in past to animate text changes:

<TextBox Text="123">
    <TextBox.Triggers>
        <EventTrigger RoutedEvent="TextBox.TextChanged">
            <BeginStoryboard>
                <Storyboard FillBehavior="Stop">
                    <DoubleAnimation Storyboard.TargetProperty="Opacity"
                                     To="0"
                                     Duration="0:0:.5" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </TextBox.Triggers>
</TextBox>
Sinatr
  • 20,892
  • 15
  • 90
  • 319
0

In XAML :

<TextBox TextChanged="TextBox_TextChanged"/>

Code Behind :

private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
    TextBox textBox = sender as TextBox;
}

'TextBox_TextChanged' this event will get triggered whenever user will change the text inside the textbox.

SAT
  • 192
  • 2
  • 15