【问题标题】:judge if the content in the textbox changes [duplicate]判断文本框中的内容是否发生变化[重复]
【发布时间】:2017-08-29 08:05:41
【问题描述】:

我有一个 C# WPF 问题。我需要设置一个触发事件来检查文本框中的内容是否已更改。无论用户在文本框中添加或删除任何字符,我都可以将其作为触发事件。这个怎么做?谢谢。

【问题讨论】:

  • @ASh,OP 说“触发事件”不是 binding,也不是 setter
  • @Sinatr,我的心灵感应调试协处理器出现故障,可能会返回误报。很高兴你没事,而且你有足够的精力按需编写代码

标签: c# wpf textbox


【解决方案1】:

在 XAML 中:

<TextBox TextChanged="TextBox_TextChanged"/>

代码背后:

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

'TextBox_TextChanged' 只要用户更改文本框内的文本,就会触发此事件。

【讨论】:

    【解决方案2】:

    我过去做过类似的事情来动画文本更改:

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-11
      • 2017-04-21
      • 2017-01-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多