Silverlight: How to receive notification of a change in an inherited DependencyProperty

前端 未结 5 1563
无人共我
无人共我 2020-12-24 08:53

I have a control which inherits from (you guessed it) Control. I want to receive a notification whenever the FontSize or Style properties are chang

5条回答
  •  旧巷少年郎
    2020-12-24 09:32

    It's a rather disgusting hack, but you could use a two-way binding to simulate this.

    i.e. have something like:

    public class FontSizeListener {
        public double FontSize {
            get { return fontSize; }
            set { fontSize = value; OnFontSizeChanged (this, EventArgs.Empty); }
        }
    
        public event EventHandler FontSizeChanged;
    
        void OnFontSizeChanged (object sender, EventArgs e) {
          if (FontSizeChanged != null) FontSizeChanged (sender, e);
        }
    }
    

    then create the binding like:

    
      
         
      
    
      
    
    

    then hook up to the listener's event in your control subclass.

提交回复
热议问题