本文整理汇总了C#中ReactiveCommand类的典型用法代码示例。如果您正苦于以下问题:C# ReactiveCommand类的具体用法?C# ReactiveCommand怎么用?C# ReactiveCommand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReactiveCommand类属于命名空间,在下文中一共展示了ReactiveCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MyPageViewModel
public MyPageViewModel(ITicketService ticketService, ITicketMapper mapper)
{
_ticketService = ticketService;
_mapper = mapper;
LoadTickets = new ReactiveAsyncCommand(null, 1, RxApp.DeferredScheduler);
LoadTickets.RegisterAsyncFunction(x => loadTickets())
.ToProperty(this, x => x.Tickets);
Observable.Interval(TimeSpan.FromSeconds(10), RxApp.DeferredScheduler)
.InvokeCommand(LoadTickets);
LoadTickets.Execute(null);
_redmineBaseUrl = ConfigurationManager.AppSettings["Redmine.BaseRedmineUrl"];
SortBy = new List<SortByModel>()
{
new SortByModel("Project", c => c.Project),
new SortByModel("Due date", c=> c.DueDate),
new SortByModel("Priority", c => c.Priority),
};
SortByCommand = new ReactiveCommand(this.WhenAny(c => c.Tickets,
((tickets) => tickets.Value != null && tickets.Value.Count > 0)));
SortByCommand.Subscribe(c => sortTickets((SortByModel)c));
}
示例2: ReactivePropertyBasicsPageViewModel
public ReactivePropertyBasicsPageViewModel()
{
// mode is Flags. (default is all)
// DistinctUntilChanged is no push value if next value is same as current
// RaiseLatestValueOnSubscribe is push value when subscribed
var allMode = ReactivePropertyMode.DistinctUntilChanged | ReactivePropertyMode.RaiseLatestValueOnSubscribe;
// binding value from UI Control
// if no set initialValue then initialValue is default(T). int:0, string:null...
InputText = new ReactiveProperty<string>(initialValue: "", mode: allMode);
// send value to UI Control
DisplayText = InputText
.Select(s => s.ToUpper()) // rx query1
.Delay(TimeSpan.FromSeconds(1)) // rx query2
.ToReactiveProperty(); // convert to ReactiveProperty
ReplaceTextCommand = InputText
.Select(s => !string.IsNullOrEmpty(s)) // condition sequence of CanExecute
.ToReactiveCommand(); // convert to ReactiveCommand
// ReactiveCommand's Subscribe is set ICommand's Execute
// ReactiveProperty.Value set is push(& set) value
ReplaceTextCommand.Subscribe(_ => InputText.Value = "Hello, ReactiveProperty!");
}
示例3: MainViewModel
public MainViewModel()
{
_informationEngine = new InformationEngine();
_sessionViewModels =
_informationEngine.Sessions.CreateDerivedCollection(x => new SessionViewModel(x) as ISessionViewModel);
((IEditableCollectionView) (CollectionViewSource.GetDefaultView(_sessionViewModels)))
.NewItemPlaceholderPosition = NewItemPlaceholderPosition.AtEnd;
_showInitializationErrorMessage = () => MessageBox.Show(
"Bei der Initialisierung des Receivers ist ein Fehler aufgetreten.\n" +
"Bitte schließen Sie die Session und starten den Receiver neu.",
"Fehler");
_showCloseSessionErrorMessage = () => MessageBox.Show(
"Beim Schließen der Session trat ein Fehler auf.",
"Fehler");
StartNewSessionCommand = new ReactiveCommand();
StartNewSessionCommand.Subscribe(_ => StartNewSession());
InitializeReceiverCommand = new ReactiveAsyncCommand();
InitializeReceiverCommand.RegisterAsyncAction(x => InitializeReceiver((Tuple<Guid, IReceiver>) x));
InitializeReceiverCommand.ThrownExceptions.Subscribe(
ex => _showInitializationErrorMessage());
CloseSessionCommand = new ReactiveCommand();
CloseSessionCommand.Subscribe(x => CloseSession((ISessionViewModel) x));
CloseSessionCommand.ThrownExceptions.Subscribe(ex => _showCloseSessionErrorMessage());
}
示例4: OpenFileTabContentViewModel
public OpenFileTabContentViewModel(IDialogService dialogService)
{
this.dialogService = dialogService;
openFileCommand = ReactiveCommand.Create();
openFileCommand.Subscribe(_ => OpenFile());
}
示例5: PersonListViewModel
public PersonListViewModel(IScreen hostScreen, IPersonRepository personRepository = null)
{
HostScreen = hostScreen;
personRepository = personRepository ?? new PersonRepository();
Persons = new ReactiveList<PersonItemViewModel>();
NewPersonCommand = new ReactiveCommand(null);
NewPersonCommand.RegisterAsyncAction(_ => { }).Subscribe(_ => HostScreen.Router.Navigate.Execute(new PersonAddViewModel(HostScreen)));
RefreshCommand = new ReactiveCommand(null);
var refresh = RefreshCommand.RegisterAsync<List<Person>>(_ => Observable.Start(() => personRepository.RetrievePersonsAsync().
Result));
refresh.Subscribe(list =>
{
using (Persons.SuppressChangeNotifications())
{
Persons.Clear();
Persons.AddRange(personRepository.RetrievePersonsAsync().
Result.Select(d => new PersonItemViewModel(d.FirstName,
d.LastName,
d.Age)));
}
});
MessageBus.Current.Listen<Person>().
Subscribe(p =>
{
personRepository.AddPerson(p);
RefreshCommand.Execute(null);
});
}
示例6: TwoFactorViewModel
public TwoFactorViewModel(IScreen host)
{
HostScreen = host;
var codeHasBeenInput = this.WhenAny(x => x.Code, code => !string.IsNullOrWhiteSpace(code.Value));
Submit = new ReactiveCommand(codeHasBeenInput);
}
示例7: AllowConcurrentExecutionTest
public void AllowConcurrentExecutionTest()
{
(new TestScheduler()).With(sched => {
var fixture = new ReactiveCommand(null, true, sched);
Assert.True(fixture.CanExecute(null));
var result = fixture.RegisterAsync(_ => Observable.Return(4).Delay(TimeSpan.FromSeconds(5), sched))
.CreateCollection();
Assert.Equal(0, result.Count);
sched.AdvanceToMs(25);
Assert.Equal(0, result.Count);
fixture.Execute(null);
Assert.True(fixture.CanExecute(null));
Assert.Equal(0, result.Count);
sched.AdvanceToMs(2500);
Assert.True(fixture.CanExecute(null));
Assert.Equal(0, result.Count);
sched.AdvanceToMs(5500);
Assert.True(fixture.CanExecute(null));
Assert.Equal(1, result.Count);
});
}
示例8: LoginRouteViewModel
public LoginRouteViewModel(IScreen hostScreen)
{
HostScreen = hostScreen;
var authentication = new Authentication();
var canLogin = this.WhenAny(x => x.LoginName,
x => x.Password,
(l, p) => !String.IsNullOrWhiteSpace(l.Value) && !String.IsNullOrWhiteSpace(p.Value));
LoginCommand = new ReactiveCommand(canLogin);
var loggedIn = LoginCommand.RegisterAsync(_ => Observable.Start(() =>
{
var authenticationResult = authentication.AuthenticateAsync(LoginName,
Password).
Result;
return authenticationResult == AuthenticationResult.Authenticated
? "Přihlášen"
: "Nepřihlášen";
}));
loggedIn.Subscribe(s =>
{
if (s == "Přihlášen")
HostScreen.Router.Navigate.Execute(new PersonListViewModel(HostScreen));
});
message = new ObservableAsPropertyHelper<string>(loggedIn,
s => raisePropertyChanged("Message"));
}
示例9: BudgetsViewModel
public BudgetsViewModel(IBudgetService budgetService, INavigationService navigationService, IBudgetSynchronizationService budgetSynchronizationService)
{
this._budgetService = budgetService;
this._navigationService = navigationService;
this._budgetSynchronizationService = budgetSynchronizationService;
var canOpenBudget = this.WhenAny(f => f.SelectedBudget, budget => budget.Value != null);
this.OpenBudget = ReactiveCommand.CreateAsyncTask(canOpenBudget, async _ =>
{
await this._budgetSynchronizationService.SynchronizeBudgetInBackground(this.SelectedBudget);
this._navigationService.NavigateToViewModel<BudgetsViewModel>();
});
this.ReloadBudgets = ReactiveCommand.CreateAsyncTask(async _ =>
{
IReadOnlyCollection<Budget> budgets = await this._budgetService.GetBudgetsAsync();
var result = new ReactiveObservableCollection<Budget>();
result.AddRange(budgets);
return result;
});
this.ReloadBudgets.ToProperty(this, f => f.Budgets, out this._budgetsHelper);
}
示例10: CoreEntityVM
/// <summary>
/// Initializes a new instance of the <see cref="CoreEntityVM"/> class.
/// </summary>
protected CoreEntityVM()
{
#region Register Commands
//Can save or discard when context has changes and is not submitting
var canSaveDiscardCommand =
DataManager.DomainContextHasChangesObservable.CombineLatest(DataManager.DomainContextIsSubmittingObservable,
(hasChanges, isSubmitting) => hasChanges && !isSubmitting);
SaveCommand = new ReactiveCommand(canSaveDiscardCommand);
SaveCommand.ObserveOnDispatcher().Subscribe(param =>
{
if (!BeforeSaveCommand()) return;
DataManager.EnqueueSubmitOperation(OnSave);
});
DiscardCommand = new ReactiveCommand(canSaveDiscardCommand);
DiscardCommand.ObserveOnDispatcher().Subscribe(param =>
{
if (!BeforeDiscardCommand()) return;
DomainContext.RejectChanges();
AfterDiscard();
DiscardSubject.OnNext(true);
});
#endregion
}
示例11: SetConfigurationMenu
void SetConfigurationMenu(MainWindowViewModel viewModel)
{
ConfigurationContextMenu.Items.Clear();
foreach (var item in viewModel.Configrations)
{
ConfigurationContextMenu.Items.Add(new MenuItem { FontSize = 12, Header = item.Item1, Command = item.Item2 });
}
ConfigurationContextMenu.Items.Add(new Separator());
var saveCommand = new ReactiveCommand();
saveCommand.Subscribe(_ =>
{
var dialog = new Microsoft.Win32.SaveFileDialog();
dialog.FilterIndex = 1;
dialog.Filter = "JSON Configuration|*.json";
dialog.InitialDirectory = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "configuration");
if (dialog.ShowDialog() == true)
{
var fName = dialog.FileName;
if (!fName.EndsWith(".json")) fName = fName + ".json";
viewModel.SaveCurrentConfiguration(fName);
viewModel.LoadConfigurations();
SetConfigurationMenu(viewModel); // reset
}
});
ConfigurationContextMenu.Items.Add(new MenuItem { FontSize = 12, Header = "Save...", Command = saveCommand });
}
示例12: RepositoryOutlinerVm
public RepositoryOutlinerVm(RepositoryVm repos)
: base(string.Empty, RepositoryOutlinerItemType.Root, null, repos, null)
{
Debug.Assert(repos != null);
_repos = repos;
SelectedItem = new ReactiveProperty<RepositoryOutlinerItemVm>()
.AddTo(MultipleDisposable);
// 各項目のルートノードを配置する
_localBranch =
new RepositoryOutlinerItemVm("Local", RepositoryOutlinerItemType.LocalBranchRoot, null, repos, this)
.AddTo(MultipleDisposable);
_remoteBranch =
new RepositoryOutlinerItemVm("Remote", RepositoryOutlinerItemType.RemoteBranchRoot, null, repos, this)
.AddTo(MultipleDisposable);
Children.AddOnScheduler(_localBranch);
Children.AddOnScheduler(_remoteBranch);
UpdateBranchNodes(_localBranch, repos.LocalBranches, false);
UpdateBranchNodes(_remoteBranch, repos.RemoteBranches, true);
repos.LocalBranches.CollectionChangedAsObservable()
.Subscribe(_ => UpdateBranchNodes(_localBranch, repos.LocalBranches, false))
.AddTo(MultipleDisposable);
repos.RemoteBranches.CollectionChangedAsObservable()
.Subscribe(_ => UpdateBranchNodes(_remoteBranch, repos.RemoteBranches, true))
.AddTo(MultipleDisposable);
SwitchBranchCommand = new ReactiveCommand().AddTo(MultipleDisposable);
SwitchBranchCommand.Subscribe(_ => SwitchBranch()).AddTo(MultipleDisposable);
}
示例13: IndexViewModel
public IndexViewModel(IRepository repo)
{
this.repo = repo;
this.refreshCommand = ReactiveCommand.Create();
this.repositoryStatus = this.refreshCommand.Select(u =>
{
return repo.RetrieveStatus(new StatusOptions() { Show = StatusShowOption.IndexAndWorkDir });
}).ToProperty(this, vm => vm.RepositoryStatus);
this.statusEntries = this
.WhenAny(vm => vm.RepositoryStatus, change =>
{
var status = change.GetValue();
return status.CreateDerivedCollection(s => s, null, null, null, this.refreshCommand);
}).ToProperty(this, vm => vm.StatusEntries);
var resetSignal = this.WhenAny(vm => vm.StatusEntries, change =>
{
return 0;
});
var allEntries = this.WhenAny(vm => vm.StatusEntries, change => change.GetValue());
this.unstagedEntries = allEntries.Select(s =>
{
return s.CreateDerivedCollection(i => i, i => Unstaged(i.State), null, resetSignal);
}).ToProperty(this, vm => vm.UnstagedEntries);
this.stagedEntries = allEntries.Select(s =>
{
return s.CreateDerivedCollection(i => i, i => Staged(i.State), null, resetSignal);
}).ToProperty(this, vm => vm.StagedEntries);
}
示例14: MainWindowViewModel
public MainWindowViewModel(ISentenceFactory sentenceFactory)
{
_sentenceFactory = sentenceFactory;
CreateSentenceCommand = new ReactiveCommand(this.WhenAny(x => x.NewSentence, x => !string.IsNullOrEmpty(x.Value)));
CreateSentenceCommand.Subscribe(_ => CreateSentence());
}
示例15: OpenDatabaseViewModel
public OpenDatabaseViewModel(
INavigationService navigationService,
IDatabaseInfoRepository databaseInfoRepository,
ICanSHA256Hash hasher,
IDialogService dialogService,
IPWDatabaseDataSource databaseSource,
ICache cache)
{
_cache = cache;
_databaseSource = databaseSource;
_dialogService = dialogService;
_databaseInfoRepository = databaseInfoRepository;
_hasher = hasher;
_navigationService = navigationService;
var canHitOpen = this.WhenAny(
vm => vm.Password,
vm => vm.KeyFileName,
(p, k) => !string.IsNullOrEmpty(p.Value) || !string.IsNullOrEmpty(k.Value));
OpenCommand = new ReactiveCommand(canHitOpen);
OpenCommand.Subscribe(OpenDatabase);
GetKeyFileCommand = new ReactiveCommand();
GetKeyFileCommand.Subscribe(GetKeyFile);
ClearKeyFileCommand = new ReactiveCommand();
ClearKeyFileCommand.Subscribe(ClearKeyFile);
IObservable<string> keyFileNameChanged = this.WhenAny(vm => vm.KeyFileName, kf => kf.Value);
keyFileNameChanged.Subscribe(v => ClearKeyFileButtonIsVisible = !string.IsNullOrWhiteSpace(v));
keyFileNameChanged.Subscribe(v => GetKeyFileButtonIsVisible = string.IsNullOrWhiteSpace(v));
}