Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. //in the viewmodel
  2. class MainViewModel : ReactiveObject
  3. {
  4. public ReactiveUI.ReactiveCommand<Unit, Unit> MyReactiveCommand { get; }
  5.  
  6. public MainViewModel()
  7. {
  8. MyReactiveCommand = ReactiveCommand.Create(() => { MessageBox.Show("Hello"); }, outputScheduler: RxApp.MainThreadScheduler);
  9. }
  10. }
  11.  
  12. //in the view xaml
  13. <Window.DataContext>
  14. <local:MainViewModel/>
  15. </Window.DataContext>
  16.  
  17. <Grid>
  18. <WrapPanel HorizontalAlignment = "Left">
  19. <Button Content="button" Command="{Binding MyReactiveCommand}"/>
  20. </WrapPanel>
  21. </Grid>
  22.  
  23. public class MainViewModel : ReactiveObject
  24. {
  25. public ReactiveCommand<Unit, Unit> MyReactiveCommand { get; }
  26.  
  27. public MainViewModel()
  28. {
  29. MyReactiveCommand = ReactiveCommand.CreateFromObservable(DoSometing);
  30. MyReactiveCommand.Subscribe(x => { MessageBox.Show("Hello"); });
  31. }
  32.  
  33. public IObservable<Unit> DoSometing()
  34. {
  35. return Observable.Start(() => { });
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement