Bind IsEnabled property to Boolean in WPF

后端 未结 1 1194
予麋鹿
予麋鹿 2021-01-21 02:04

I have a TextBox which needs to be enabled / disabled programmatically. I want to achieve this using a binding to a Boolean. Here is the TextBox<

1条回答
  •  [愿得一人]
    2021-01-21 02:30

    Here are your little typos!

        private Boolean _textbox_enabled;
        public Boolean TextboxEnabled // here, underscore typo
        {
            get { return _textbox_enabled; }
            set
            {
                _textbox_enabled = value; // You miss this line, could be ok to do an equality check here to. :)
                OnPropertyChanged("TextboxEnabled"); // 
            }
        }
    

    Another thing for your xaml to update the text to the vm/datacontext

    Text="{Binding Path=Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding TextBoxEnabled}"/>
    

    0 讨论(0)
提交回复
热议问题