本文整理汇总了C#中ReactiveCommand类的典型用法代码示例。如果您正苦于以下问题:C# ReactiveCommand类的具体用法?C# ReactiveCommand怎么用?C# ReactiveCommand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReactiveCommand类属于命名空间,在下文中一共展示了ReactiveCommand类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
}
开发者ID:sTodorov,项目名称:bugmine,代码行数:28,代码来源:MyPageViewModel.cs
示例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!");
}
开发者ID:neuecc,项目名称:ReactiveProperty,代码行数:25,代码来源:ReactivePropertyBasicsPageViewModel.cs
示例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());
}
开发者ID:GraphalyzerPro,项目名称:GraphalyzerPro,代码行数:29,代码来源:MainViewModel.cs
示例4: OpenFileTabContentViewModel
public OpenFileTabContentViewModel(IDialogService dialogService)
{
this.dialogService = dialogService;
openFileCommand = ReactiveCommand.Create();
openFileCommand.Subscribe(_ => OpenFile());
}
开发者ID:402214782,项目名称:mvvm-dialogs,代码行数:7,代码来源:OpenFileTabContentViewModel.cs
示例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);
});
}
开发者ID:jiravanet,项目名称:Prezentace-ReactiveUI,代码行数:28,代码来源:PersonListViewModel.cs
示例6: TwoFactorViewModel
public TwoFactorViewModel(IScreen host)
{
HostScreen = host;
var codeHasBeenInput = this.WhenAny(x => x.Code, code => !string.IsNullOrWhiteSpace(code.Value));
Submit = new ReactiveCommand(codeHasBeenInput);
}
开发者ID:jugglingnutcase,项目名称:StarHub,代码行数:7,代码来源:TwoFactorViewModel.cs
示例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);
});
}
开发者ID:niefan,项目名称:ReactiveUI,代码行数:27,代码来源:ReactiveCommandTest.cs
示例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"));
}
开发者ID:jiravanet,项目名称:Prezentace-ReactiveUI,代码行数:25,代码来源:LoginRouteViewModel.cs
示例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);
}
开发者ID:haefele,项目名称:SavvyOld,代码行数:25,代码来源:BudgetsViewModel.cs
示例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
}
开发者ID:FoundOPS,项目名称:server,代码行数:31,代码来源:CoreEntityVM.cs
示例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 });
}
开发者ID:neuecc,项目名称:PhotonWire,代码行数:27,代码来源:MainWindow.xaml.cs
示例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);
}
开发者ID:YoshihiroIto,项目名称:Anne,代码行数:35,代码来源:RepositoryOutlinerVm.cs
示例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);
}
开发者ID:abbottdev,项目名称:gitreminder,代码行数:35,代码来源:IndexViewModel.cs
示例14: MainWindowViewModel
public MainWindowViewModel(ISentenceFactory sentenceFactory)
{
_sentenceFactory = sentenceFactory;
CreateSentenceCommand = new ReactiveCommand(this.WhenAny(x => x.NewSentence, x => !string.IsNullOrEmpty(x.Value)));
CreateSentenceCommand.Subscribe(_ => CreateSentence());
}
开发者ID:darkmyst,项目名称:DnDEventLog,代码行数:7,代码来源:MainWindowViewModel.cs
示例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));
}
开发者ID:TheAngryByrd,项目名称:MetroPass,代码行数:32,代码来源:OpenDatabaseViewModel.cs
示例16: MainWindowViewModel
public MainWindowViewModel()
{
var whenAnyColorChanges = this.WhenAny(x => x.Red, x => x.Green, x => x.Blue,
(r, g, b) => Tuple.Create(r.Value, g.Value, b.Value))
.Select(intsToColor);
_FinalColor = whenAnyColorChanges
.Where(x => x != null)
.Select(x => x.Value)
.ToProperty(this, x => x.FinalColor);
Ok = ReactiveCommand.Create(whenAnyColorChanges.Select(x => x != null));
_Images = this.WhenAny(x => x.FinalColor, x => x.Value)
.Throttle(TimeSpan.FromSeconds(0.7), RxApp.MainThreadScheduler)
.Do(_ => IsBusy = true)
.Select(x => imagesForColor(x))
.Switch()
.SelectMany(imageListToImages)
.ObserveOn(RxApp.MainThreadScheduler)
.Do(_ => IsBusy = false)
.ToProperty(this, x => x.Images);
_Images.ThrownExceptions.Subscribe(ex => this.Log().WarnException("Can't load images", ex));
}
开发者ID:modulexcite,项目名称:RxUI_QCon,代码行数:25,代码来源:MainWindowViewModel.cs
示例17: MainVM
public MainVM()
{
var bobbyJoe = new Person("Bobby Joe", new[] { new Pet("Fluffy") });
var bob = new Person("Bob", new[] { bobbyJoe });
var littleJoe = new Person("Little Joe");
var joe = new Person("Joe", new[] { littleJoe });
Family = new ReactiveList<TreeItem> { bob, joe };
_addPerson = ReactiveCommand.Create();
_addPerson.Subscribe(_ =>
{
if (SelectedItem == null) return;
var p = new Person(NewName);
SelectedItem.AddChild(p);
p.IsSelected = true;
p.ExpandPath();
});
_addPet = ReactiveCommand.Create();
_addPet.Subscribe(_ =>
{
if (SelectedItem == null) return;
var p = new Pet(PetName);
SelectedItem.AddChild(p);
p.IsSelected = true;
p.ExpandPath();
});
_collapse = ReactiveCommand.Create();
_collapse.Subscribe(_ =>
{
SelectedItem?.CollapsePath();
});
}
开发者ID:reactiveui-forks,项目名称:ReactiveUI-TreeView,代码行数:32,代码来源:MainVM.cs
示例18: PostListViewModel
public PostListViewModel()
{
service = new PostService();
var filters = MessageBus.Current.Listen<PostFilter>(MessageTypes.CurrentPostFilter)
.Throttle(TimeSpan.FromSeconds(0.7), RxApp.DeferredScheduler);
var refreshRequests = new ReactiveCommand();
GlobalCommands.RefreshCommand.RegisterCommand(refreshRequests);
var filtersToRefresh = refreshRequests
.Select((_, i) => i)
.CombineLatest(filters, (i, f) => new {CommandId = i, Filter = f})
.DistinctUntilChanged(x => x.CommandId)
.Select(x => x.Filter);
var results = filters.Merge(filtersToRefresh)
.ObserveOn(RxApp.TaskpoolScheduler)
.Select(x => new { TargetFilter = x, Value = service.GetPosts(x) });
var latestResults = filters
.CombineLatest(results, (f, r) => new { LatestFilter = f, LatestResult = r })
.Where(x => Equals(x.LatestFilter, x.LatestResult.TargetFilter))
.Select(x => x.LatestResult);
latestResults
.Select(x => x.Value.Select(p => new PostViewModel
{
Title = p.Title,
FeedName = p.FeedName,
FeedImage = new Uri(p.FeedImage),
PublicationDate = p.PublicationDate
}).ToList())
.ToProperty(this, x => x.Posts);
}
开发者ID:r0t0r-r0t0r,项目名称:YandexSubscriptionsClient,代码行数:35,代码来源:PostListViewModel.cs
示例19: FolderBrowserTabContentViewModel
public FolderBrowserTabContentViewModel(IDialogService dialogService)
{
this.dialogService = dialogService;
browseFolderCommand = ReactiveCommand.Create();
browseFolderCommand.Subscribe(_ => BrowseFolder());
}
开发者ID:402214782,项目名称:mvvm-dialogs,代码行数:7,代码来源:FolderBrowserTabContentViewModel.cs
示例20: OpenCacheViewModel
public OpenCacheViewModel(IScreen hostScreen, IAppState appState)
{
HostScreen = hostScreen;
var isCachePathValid = this.WhenAny(
x => x.CachePath, x => x.OpenAsEncryptedCache, x => x.OpenAsSqlite3Cache,
(cp, _, sql) => new { Path = cp.Value, Sqlite3 = sql.Value })
.Throttle(TimeSpan.FromMilliseconds(250), RxApp.MainThreadScheduler)
.Select(x => x.Sqlite3 ? File.Exists(x.Path) : Directory.Exists(x.Path));
OpenCache = new ReactiveCommand(isCachePathValid);
OpenCache.SelectMany(_ => openAkavacheCache(CachePath, OpenAsEncryptedCache, OpenAsSqlite3Cache))
.LoggedCatch(this, Observable.Return<IBlobCache>(null))
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(x => {
if (x == null) {
UserError.Throw("Couldn't open this cache");
return;
}
appState.CurrentCache = x;
hostScreen.Router.Navigate.Execute(new CacheViewModel(hostScreen, appState));
});
}
开发者ID:pisees,项目名称:AkavacheExplorer,代码行数:25,代码来源:OpenCacheViewModel.cs
注:本文中的ReactiveCommand类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论