← All lessons

Level 1 / XAML + MVVM / lesson 6 of 6

Binding state, not just text

Drive a control's enabled state from the view model and flip it with a command.

Bindings are not only for text. Any bindable property can be driven from the view model, which is how a screen stays in one consistent state instead of drifting apart from the data behind it.

Understand the idea

Binding beyond text

A control's IsEnabled property can follow CanSubmit. If CanSubmit raises PropertyChanged, the control responds when the value changes.

Two ways to express availability

IsEnabled is view state; ICommand.CanExecute describes whether a command can run. For an action button, consider using CanExecute so both interaction and command execution follow the same rule.

A disabled control is not validation

Disabling a button improves feedback but is not a substitute for validating data or permissions when an action is executed.

13 lines
5 lines

Preview - simulated. Not a .NET compiler.

Step 1 of 3

In progress

Bind the enabled state

Bind the Submit button's IsEnabled to CanSubmit.

  • A Button binds IsEnabled to CanSubmit - not done yet

Coach

The checklist above is what decides whether a step is done. The coach only explains; it never grades.

The preview is a simulated XAML surface, not WPF, WinUI, or .NET MAUI. It renders StackPanel, Grid, TextBlock, Label, TextBox, Entry, and Button, and simulates INotifyPropertyChanged and ICommand. Layout attributes such as Margin and Width are accepted but not laid out. Anything else is reported as outside the lesson.

Where the simulator stops

The simulator models simple IsEnabled bindings and a toggle command, not the full ICommand.CanExecute lifecycle or platform-specific validation.

Try it in a real .NET project

Bind a WPF Submit button's IsEnabled to a notifying CanSubmit property and toggle it from a command. Then try implementing CanExecute on the Submit command, raising CanExecuteChanged when availability changes.

Check your understanding

Is disabling Submit with IsEnabled enough to enforce that an operation is allowed?

Show the explanation

No. It gives UI feedback, but the operation still needs validation and authorization when executed. ICommand.CanExecute can coordinate the button state with command availability.

Goose School teaches Microsoft's stack. Goose Solutions is not affiliated with, endorsed by, or sponsored by Microsoft.