Button
Interactive button with ICommand binding, hover/focus colors, and keyboard support.
Overview
The Button control inherits from ButtonBase and supports the
WPF ICommand pattern via the Command property. Buttons respond
to Enter/Space keys when focused and mouse clicks. Visual states include focus and hover border colors.
ViewModel (C#)
Each button is wired to a RelayCommand that increments a click counter and records the last action.
public class ButtonsViewModel : ViewModelBase
{
public int ClickCount { get; private set => SetProperty(ref field, value); }
public string LastAction { get; set => SetProperty(ref field, value); } = "No button clicked yet";
public ICommand NewCommand => field ??= new RelayCommand(() =>
{
ClickCount++;
LastAction = $"New clicked (total: {ClickCount})";
});
}
Key Concepts
Command="{Binding ...}"for MVVM command bindingRelayCommandwith parameterless and parameterized constructorsHoverColorandFocusColorfor visual statesTabIndexfor keyboard navigation orderWidthandHeightwithSize.Absolutevalues