Handle event when Label Text Change

前端 未结 2 986
执笔经年
执笔经年 2021-01-28 17:24

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)

相关标签:
2条回答
  • 2021-01-28 17:36

    What you can do is on whatever page/view your label is on create a new bindableproperty that is set to your binding. Then add a propertyChanged method that will get called if the text on your label changes.

     public static BindableProperty TextChangedProperty = BindableProperty.Create(nameof(TextChanged), typeof(string), typeof(YourView), string.Empty,  propertyChanged:OnTextChanged);
    
     public string TextChanged
     {
         get { return (string)GetValue(TextChangedProperty); }
         set { SetValue(TextChangedProperty, value); }
     }
    
     static void OnTextChanged(BindableObject bindable, object oldValue, object newValue)
     {
        //Do stuff
     }
    
    0 讨论(0)
  • 2021-01-28 17:52

    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
        }
    }
    
    0 讨论(0)
提交回复
热议问题