Unable to set button.IsEnabled = true in C # WPF

This question is as simple as it seems. Suppose button.IsEnabled == false when I execute button.IsEnabled = true; the button remains false! (Using the "watch" function of Visual Studio to immediately look at the value after installation in the debugger)

Obviously, this is not a common occurrence; as a rule, this code works. But there is something in the system that blocks the setup, and I'm looking for ideas about what it might be. At first I thought that this happened because the button was connected to ICommand, which obviously controls the IsEnabled parameter itself. Therefore, I excluded ICommand. This worked for another button, but this button is not connected to ICommand via "Command = {Binding Path ...}". In fact, this button is created in C # as simply:

Button button = new Button();
button.Content = "Save Record";
button.IsTabStop = false;

These buttons exist on the user control toolbar, and the code that tries to set their value is found in the PropertyChanged event handler that I wrote. Curiously, the same code initially successfully sets the button to false, and it works! What could be to prohibit setting IsEnabled = true?

A few hours later:

Bah, rookie mistake (after 35 years in IT). Next in the code was a line:

button.Command = new myCommand(...); 

, . clickhandler, . Google, , , : ICommand UIElement, . , menuitem . .NET IsEnabled. .

+3
1

, , , . , , , , .

- Event! IsEnabled Click, .

- , IsEnabled Click .

"IsEnabled = True" True CanExecute .

Executed Command, Click.

? : , , , , , ( ) "" . . "" > "", " " ; TextBox SelectionChanged, / ; Click . : "" > "", " " , "CanExecute" true/false TextBox Executed. ? , , . , .

+2
source

All Articles