标签文本更改时处理事件 [英] Handle event when Label Text Change

查看:99
本文介绍了标签文本更改时处理事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发与RFID读取器通信的App,我有以下标签,它从读取器中获取它的值(当我单击硬件上的读取按钮时)

I'm developing App which communicate with RFID Reader, I have the following Label which takes it's value from the Reader (when I click on the read button on the hardware)

<Label Text="{Binding Statistics.TotalUniqueCount}" />

当文本值更改时,我想处理和事件,标签似乎没有此类事件,是否有任何文本视图控件可以处理文本更改事件?我尝试使用Entry控制,但是这个问题是,当我读取RFID标签时,它给我第一次和第二次正确的值,而第三次给我错误的值,并且仅当我使用Entry时才会发生. 例如,我读取了3个唯一标签,它第一次给我3,当我读取更多2个标签时,数字变成5,但是当我第三次读取另外3个标签时,数字变成1. 我将Entry和Label放在具有相同绑定的同一页面中,Label显示正确的值,而Entry显示错误的值.

I want to handle and event when the text value changed, it looks like the label doesn't has such event, is there any text view control that can handle the text change event? I tried to use Entry control, but the problem that when I read the RFID tags, it gives me the first and second time correct values, but the third time it gives me wrong value , and that's happens only when I use Entry. for example, I read 3 unique tags, it gives me first time 3, when I read more 2 tags, the number becomes 5, but when I read the third time another 3 tags, the number becomes 1. I put Entry and Label in the same page with the same Binding, the Label shows correct values and the Entry shows wrong values.

当此绑定(Statistics.TotalUniqueCount)更改时,有什么解决方案可以处理事件?

is there any solution to handle event when this binding (Statistics.TotalUniqueCount) changes?

推荐答案

如注释中所述,Statistics类似乎必须实现INotifyPropertyChanged(这是绑定能够在数据更改时更新UI的方式).如果是这样,您应该只在代码中订阅相同的事件.不论您在何处访问该Statistics变量(在代码隐藏或在viewmodel中),只需执行

As was mentioned in the comments, it looks like the Statistics class must implement INotifyPropertyChanged (that's how the binding is able to update the UI when the data changes). If that's the case, you should just subscribe to that same event in your code. Wherever you have access to that Statistics variable (in code bebhind or viewmodel), just do

Statistics.PropertyChanged += (o,e)=> 
{ 
    if (e.PropertyName = "TotalUniqueCount")
    {
      //do something
    }
}

这篇关于标签文本更改时处理事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆