Binding on DependencyProperty of custom User Control not updating on change

后端 未结 2 922
死守一世寂寞
死守一世寂寞 2021-01-17 13:16

I\'m having difficulties with databinding on my custom user control (s). I created an example project to highlight my problem. I\'m completely new to WPF and essentially MVV

2条回答
  •  离开以前
    2021-01-17 13:18

    I tried your code works fine the only change i made was to remove the code behind propertychangedcallback you have and databind the Label (Readout) to the dependency property.

    USERCONTROL(XAML)

    
       
           
    
    

    USERCONTROL (CODE BEHIND)

    public partial class UserControl1 : UserControl
    {
        #region Dependency Properties
        public static readonly DependencyProperty MinutesRemainingProperty =
                    DependencyProperty.Register
                    (
                        "MinutesRemaining", typeof(int), typeof(UserControl1),
                        new UIPropertyMetadata(10)
                    );
        #endregion
    
        public int MinutesRemaining
        {
            get
            {
                return (int)GetValue(MinutesRemainingProperty);
            }
            set
            {
                SetValue(MinutesRemainingProperty, value);
            }
        }
    
       public UserControl1()
        {
            InitializeComponent();
        }
    }
    

提交回复
热议问题