wpf - How to enable a button when a user types into a textbox -
What is the easiest way to enable a button in WPF when the user is in some < Code> Text Box ?
Use simple command
& lt; Text box text = {binding path = title text} /> & Lt; Button command = "{binding path = clear text command}" content = "clear text" /> Here is sample code in visual model
public class MyViewModel: INotifyPropertyChanged {public ICommand ClearTextCommand {get; Private set; } Private string _titleText; Public string title text {received {back _titleText; } Set {if (value == _titleText) return; _titleText = Values; This.OnPropertyChanged ("TitleText"); }} Public MyViewModel () {ClearTextCommand = New SimpleCommand {ExecuteDelegate = x = & gt; TitleText = "", CanExecuteDelegate = x = & gt; TitleText.Length & gt; 0}; } Private Event PropertyChangedEventHandler PropertyChanged; Protected Zero OnPropertyChanged (string propertyName) {PropertyChangedEventHandler Handler = this.PropertyChanged; If (handler! = Null) handler (this, new property changed event event (property name)); }} See Marlon Grech for more information
Also see the MVVM project template / toolkit. It uses delegation commands for commanding and this should be a great initial template for any project.
Comments
Post a Comment