1、写一个监听值变化的类

public class MonitorValueChange
    {
        private Visibility myValue;
        public Visibility MyValue
        {
            get { return myValue; }
            set
            {
                if (value != myValue)
                {
                    WhenMyValueChange();
                }
                myValue = value;
            }
        }
        //定义的委托
        public delegate void MyValueChanged(object sender, EventArgs e);
        //与委托相关联的事件
        public event MyValueChanged OnMyValueChanged;
        //事件触发函数
        private void WhenMyValueChange()
        {
            if (OnMyValueChanged != null)
            {
                OnMyValueChanged(this, null);

            }
        }

    }

  2、调用该类监听数据

MonitorValueChange change = new MonitorValueChange();
change.MyValue = Visibility.Visible;
change.OnMyValueChanged += Change_OnMyValueChanged;
change.MyValue = Visibility.Collapsed;

private void Change_OnMyValueChanged(object sender, EventArgs e)
{
   //要做的操作
}

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-02
  • 2021-10-28
  • 2021-07-23
  • 2021-10-18
猜你喜欢
  • 2022-02-02
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2021-07-16
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案