简体   繁体   English

如何检查文字是否被更改?

[英]How to check that text is changed?

I am just start to learn WPF and have a questions: 我才刚刚开始学习WPF并有一个问题:

My DataContext is some XElement with attribute str, in markup I added: 我的DataContext是带有属性str的一些XElement,在标记中我添加了:

        <TextBox x:Name="NumStr" HorizontalAlignment="Left" Height="23" Margin="10,257,0,0" TextWrapping="Wrap" Text="{Binding Path = Attribute[str].Value}" VerticalAlignment="Top" Width="120"/>

Now if text in NumStr is changed I want to create some code: 现在,如果更改了NumStr中的文本,我想创建一些代码:

if (element.Attribute("str")?.Value != NumStr.Text && NumStr.Text != "")
                ContentFormControl.AddNumStr(fullPath, NumStr.Text);

But text in element.Attribute("str")?.Value change at the same time with NumStr.Text. 但是element.Attribute(“ str”)?. Value中的文本与NumStr.Text同时更改。 How I can correctly check, that text is change. 我如何正确检查文本是否更改。 Create other variable I won't. 创建其他我不会的变量。

Thanks for answers, and sorry for my english. 感谢您的回答,对不起我的英语。

Change the Text property binding to OneWay: 将Text属性绑定更改为OneWay:

Text="{Binding Path=Attribute[str].Value, Mode=OneWay}"

in this way the source property will not be updated every time you change the TextBox's text 这样,每次更改TextBox的文本时,source属性都不会更新

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM