TemplateBinding not working for textbox text

后端 未结 2 1857
半阙折子戏
半阙折子戏 2021-01-12 03:59

I have a custom control called EnhancedTextBox which is a UserControl that has a TextBox and a Button. To the consumer I want it to mo

2条回答
  •  逝去的感伤
    2021-01-12 04:30

    You are missing the CallBack when you register the property.

    Here's a sample code.

        public bool IsSelected
        {
            get { return (bool)GetValue(IsSelectedProperty); }
            set { SetValue(IsSelectedProperty, value); }
        }
    
        public void IsSelectedChangedCallback()
        {
    
            //actions when property changed
    
        }
    
        private static void OnSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            userControl.IsSelectedChangedCallback();
        }
    
        public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(MyUserControl), new PropertyMetadata(new PropertyChangedCallback(OnSelectedChanged)));
    

提交回复
热议问题