In reactive UI, BindCommand
can bind some control to view model's property or method, e.g. method in ViewModel
that will be executed when some button in XAML
was clicked.
https://www.reactiveui.net/docs/handbook/commands/binding-commands
How do I disable or enable a set of buttons when some of them was clicked?
According to docs, BindCommand
should have 3rd argument that can accept some function, but can't find an example.
XAML
<Button Content="Start" x:Name="StartButton" />
<Button Content="Stop" x:Name="StopButton" IsEnabled="False" />
<Button Content="Pause" x:Name="PauseButton" IsEnabled="False" />
XAML.cs
// How to enable Stop and Pause when Start was clicked?
this.BindCommand(ViewModel, vm => vm.Stop, view => view.StopButton).DisposeWith(container);
this.BindCommand(ViewModel, vm => vm.Start, view => view.StartButton).DisposeWith(container);
this.BindCommand(ViewModel, vm => vm.Pause, view => view.PauseButton).DisposeWith(container);
// In plain WPF I could do modify controls inside OnClick handler
private void OnStartClick(object sender, RoutedEventArgs e)
{
// How can I do this in Reactive UI?
StopButton.IsEnabled = true;
PauseButton.IsEnabled = true;
}
View Model
public DashboardViewModel(IScreen screen)
{
HostScreen = screen;
// Or how to get access to controls in these event handlers?
Stop = ReactiveCommand.Create(() => {});
Start = ReactiveCommand.Create(() => {});
Pause = ReactiveCommand.Create(() => {});
}