c# - WPF Data Binding : enable/disable a control based on content of var? -


I have a button on my form, which should only be enabled when an item is selected in the previewview (or list TabItem in the scene). When an item is selected, its value is stored in the string member variable.

Can I tie the isEnabled property of the button for the contents of the member word? That is, if the member var is not empty, enable the button.

Similarly, when the change in the contents of the member var (set or clear), the position of the button should change.

Since you are looking to bind the IsEnabled property of the button based on the string Try making a converter.

Ie ...

  & lt; StackPainel & gt; & Lt; StackPanel.Resources & gt; & Lt; Local: SomeStringConverter mystringtoboolconverter / & gt; & Lt; /StackPanel.Resources> & Lt; Button IsEnabled = "{binding element name = mytree, path = selected etam. Header, converter = {static resource mystringtoboolconverter}}" /> & Lt; StackPanel & gt; And converter: [value conversion (typef (string), typef (boole)] class some string converter: IValueConverter {public object convert (object value, type type type Object parameter, CultureInfo Culture) {string myheader = (string) value; If (myhead == "some") {return true; } Other {return false; }} Public Object Convertback (Object Value, Type Type, Object Parameter, CultureInfo Culture) {return null; Edit}}: Since OP wanted to bind to a variable, so there is a need to do something like this: 

  Public class classes: INotifyPropertyChanged {Private string _semestring; Public string Some string {get {return_somestring;} set {_somestring = value; OnPropertyChanged ("SomeString"}}}}}} event changed the PropertyChangedEventHandler property; Protected Zero OnPropertyChanged (string propertyName) {if (this.PropertyChanged! = Null) {this.PropertyChanged (This, New PropertyChangedEventArgs (propertyName)); After this, change the above mentioned binding expression to:  
 {binding path = some strings, converter = {static resource migrotubuntu converter}} 

Note that you can update your UI To implement INOTifyPropertyChanged


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -