wpf-vb

WPF (VB)

Windows Presentation Foundation desktop UI framework using Visual Basic .NET and XAML

Details

Language / Topic
vbnetVisual Basic .NET
Category
framework
Compatible Frameworks
wpf-vb
Source
microsoft

Rules

balanced
- Implement `INotifyPropertyChanged` via a `ViewModelBase` class using `<CallerMemberName>` so property setters never hardcode string names: `Protected Sub OnPropertyChanged(<CallerMemberName> Optional name As String = Nothing) : RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(name)) : End Sub`
- Expose UI actions as `ICommand` properties with the `Command` suffix (`SaveCommand`, `DeleteCommand`) implemented as `RelayCommand` instances — bind buttons in XAML with `Command="{Binding SaveCommand}"` instead of code-behind event handlers.
- Never access `Me.Window`, `MessageBox.Show`, or any `UIElement` from inside a ViewModel — route navigation and dialog side-effects through a service interface injected into the constructor so the ViewModel stays unit-testable.
- Implement `RelayCommand` with `Custom Event CanExecuteChanged` delegating to `CommandManager.RequerySuggested` so WPF auto-evaluates button enabled state on UI interactions — for expensive `CanExecute` predicates expose a `RaiseCanExecuteChanged()` method and call it explicitly when state changes.
- Set `UpdateSourceTrigger=PropertyChanged` on `TextBox` bindings that need immediate validation feedback, paired with `ValidatesOnDataErrors=True` to surface `IDataErrorInfo` errors inline: `<TextBox Text="{Binding Username, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"/>`
- Use `AsyncRelayCommand` from `CommunityToolkit.Mvvm` (`Imports CommunityToolkit.Mvvm.Input`) for async commands — it exposes `IsRunning` to bind a progress indicator and prevents double-submission automatically: `LoadCommand = New AsyncRelayCommand(AddressOf LoadDataAsync)`