-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathMainViewModel.cs
More file actions
56 lines (48 loc) · 1.94 KB
/
MainViewModel.cs
File metadata and controls
56 lines (48 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System.Reactive;
using System.Reactive.Linq;
using System.Windows;
namespace ReactiveUI.Winforms.Samples.Commands.ViewModels
{
public class MainViewModel : ReactiveObject
{
private string _applicationTitle;
private string _withCanExecuteParameter;
public MainViewModel()
{
// Set properties
ApplicationTitle = "ReactiveUI Winforms Samples by Asesjix - Commands";
// Create parameterless command
ParameterlessCommand = ReactiveCommand.Create(Parameterless);
// Create command with parameter
WithParameterCommand = ReactiveCommand.Create<string>(WithParameter);
// Create command with can execute
WithCanExecuteCommand = ReactiveCommand.Create(WithCanExecute,
this.WhenAnyValue(vm => vm.WithCanExecuteParameter).Select(s => string.IsNullOrEmpty(s) == false));
}
public string ApplicationTitle
{
get => _applicationTitle;
set => this.RaiseAndSetIfChanged(ref _applicationTitle, value);
}
public string WithCanExecuteParameter
{
get => _withCanExecuteParameter;
set => this.RaiseAndSetIfChanged(ref _withCanExecuteParameter, value);
}
public ReactiveCommand<Unit, Unit> ParameterlessCommand { get; }
public ReactiveCommand<string, Unit> WithParameterCommand { get; }
public ReactiveCommand<Unit, Unit> WithCanExecuteCommand { get; }
private void Parameterless()
{
MessageBox.Show("You pressed the button!", ApplicationTitle, MessageBoxButton.OK);
}
private void WithParameter(string message)
{
MessageBox.Show(message, ApplicationTitle, MessageBoxButton.OK);
}
private void WithCanExecute()
{
MessageBox.Show(WithCanExecuteParameter, ApplicationTitle, MessageBoxButton.OK);
}
}
}