本文整理汇总了C#中ReactiveList.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ReactiveList.Add方法的具体用法?C# ReactiveList.Add怎么用?C# ReactiveList.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReactiveList
的用法示例。
在下文中一共展示了ReactiveList.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ViewModel2
public ViewModel2()
{
SearchResults = new ReactiveList<FlickrPhoto>();
var canSearch = this.WhenAny(x => x.SearchTerm, x => !String.IsNullOrWhiteSpace(x.Value));
Search = ReactiveCommand.CreateAsyncTask(canSearch, async _ => { return await GetSearchResultFromBing(this.SearchTerm); });
LoadMoreItems = ReactiveCommand.CreateAsyncTask(canSearch, async x => { return await LoadMore((int)x); });
Search.Subscribe(results =>
{
SearchResults.Clear();
foreach (var item in results)
{
SearchResults.Add(item);
}
});
LoadMoreItems.Subscribe(results =>
{
foreach (var item in results)
{
SearchResults.Add(item);
}
});
Search.ThrownExceptions.Subscribe(ex => { UserError.Throw("Potential network connectivity Error", ex); });
LoadMoreItems.ThrownExceptions.Subscribe(ex => { UserError.Throw("Problem when downloading additional items", ex); });
this.WhenAnyValue(x => x.SearchTerm)
.Throttle(TimeSpan.FromSeconds(1), RxApp.MainThreadScheduler)
.InvokeCommand(this, x => x.Search);
//SearchTerm = "british cat";
}
示例2: DemoListViewPageModel
public DemoListViewPageModel()
{
DogViewModelList = new ReactiveList<DogsItemViewModel>();
DogViewModelList.Add(new DogsItemViewModel() { Name = "Rex", Race = "German Sheppard" });
DogViewModelList.Add(new DogsItemViewModel() { Name = "Barney", Race = "Poodle" });
DogViewModelList.Add(new DogsItemViewModel() { Name = "Jimmy", Race = "Beagle" });
DogViewModelList.Add(new DogsItemViewModel() { Name = "Rob", Race = "Labrador" });
}
示例3: CacheViewModel
public CacheViewModel(IScreen hostScreen, IAppState appState)
{
HostScreen = hostScreen;
appState.WhenAny(x => x.CachePath, x => x.Value)
.Where(x => !String.IsNullOrWhiteSpace(x))
.Select(x => (new DirectoryInfo(x)).Name)
.ToProperty(this, x => x.UrlPathSegment, out _UrlPathSegment);
Keys = new ReactiveList<string>();
appState.WhenAny(x => x.CurrentCache, x => x.Value)
.SelectMany(x => Observable.Start(() => x.GetAllKeys(), RxApp.TaskpoolScheduler))
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(newKeys => {
Keys.Clear();
newKeys.ForEach(x => Keys.Add(x));
});
FilteredKeys = Keys.CreateDerivedCollection(
key => key,
key => FilterText == null || key.IndexOf(FilterText, StringComparison.OrdinalIgnoreCase) > -1,
signalReset: this.WhenAny(x => x.FilterText, x => x.Value));
SelectedViewer = "Text";
this.WhenAny(x => x.SelectedKey, x => x.SelectedViewer, (k, v) => k.Value)
.Where(x => x != null && SelectedViewer != null)
.SelectMany(x => appState.CurrentCache.GetAsync(x).Catch(Observable.Return(default(byte[]))))
.Select(x => createValueViewModel(x, SelectedViewer))
.LoggedCatch(this, Observable.Return<ICacheValueViewModel>(null))
.ToProperty(this, x => x.SelectedValue, out _SelectedValue);
}
示例4: FlickrSearchViewModel
public FlickrSearchViewModel(IImageService imageService)
{
Images = new ReactiveList<SearchResultViewModel>();
var canExecute = this.WhenAnyValue(x => x.SearchText)
.Select(x => !String.IsNullOrWhiteSpace(x));
Search = ReactiveCommand.CreateAsyncObservable(
canExecute,
_ =>
{
Images.Clear();
ShowError = false;
return imageService.GetImages(SearchText);
});
Search.Subscribe(images => Images.Add(images));
Search.ThrownExceptions.Subscribe(_ => ShowError = true);
isLoading = Search.IsExecuting.ToProperty(this, vm => vm.IsLoading);
canEnterSearchText = this.WhenAnyValue(x => x.IsLoading)
.Select(x => !x)
.ToProperty(this, vm => vm.CanEnterSearchText);
}
示例5: MenuViewModel
public MenuViewModel(IUserRepository userRepository)
{
if (userRepository == null)
throw new ArgumentNullException("userRepository");
_userRepository = userRepository;
Menu = new ReactiveList<MenuOptionViewModel>();
// Use WhenAny to observe one or more values
var canLoadMenu = this.WhenAny(m => m.User, user => user.Value != null);
// hook function to command, shouldn't contain UI/complex logic
LoadMenu = ReactiveCommand.CreateAsyncTask(canLoadMenu, _ => _userRepository.GetMenuByUser(User));
// RxApp.MainThreadScheduler is our UI thread, you can go wild here
LoadMenu.ObserveOn(RxApp.MainThreadScheduler).Subscribe(menu =>
{
Menu.Clear();
foreach (var option in menu)
{
var menuOption = new MenuOptionViewModel(option);
Menu.Add(menuOption);
}
});
LoadMenu.ThrownExceptions.Subscribe(ex =>
{
Menu.Clear();
MessageBox.Show(ex.Message);
});
// Use WhenAnyValue to check if a property was changed
// If user was changed reload menu
this.WhenAnyValue(m => m.User).InvokeCommand(this, vm => vm.LoadMenu);
}
示例6: MainWindowModel
public MainWindowModel()
{
_testDataSource = new TestDataSource();
TestModels = new ReactiveList<TestModel>();
TestViewModels = TestModels.CreateDerivedCollection(m =>
{
var vm = new TestViewModel
{
Id = m.Id,
Name = m.Name,
OtherValue = "",
OriginalModel = m
};
vm.DoStuffWithThisCommand.Subscribe(x => DoStuff(x as TestViewModel));
return vm;
}, m => true, (m, vm) => 0);
SetUpDataCommand = ReactiveCommand.CreateAsyncTask(_ => _testDataSource.GetTests());
SetUpDataCommand.Subscribe(results =>
{
using (SuppressChangeNotifications())
{
TestModels.Clear();
foreach (var model in results)
TestModels.Add(model);
}
});
}
示例7: ObserveWindowViewModel
public ObserveWindowViewModel( string filename, IActorRef tailCoordinator )
{
_tailCoordinator = tailCoordinator;
Filename = filename;
Title = filename;
Items = new ReactiveList<String>();
// start coordinator
_tailCoordinator.Tell( new TailCoordinatorActor.StartTail( filename, this ) );
// this is how we can update the viewmodel
// from the actor.
Lines = new Subject<String>();
Lines.ObserveOnDispatcher().Subscribe( item =>
{
Items.Add( item );
if ( Items.Count > 1500 )
{
Items.RemoveAt( 0 );
}
SelectedLine = Items.Count - 1;
} );
}
示例8: HistoryViewModel
public HistoryViewModel(IRequestHistory requests)
{
Requests = new ReactiveList<HttpRequest>();
requests.GetRequestsAsync().ContinueWith(continuation => Requests.AddRange(continuation.Result));
requests.GetRequestsObservable().Subscribe(request => Requests.Add(request));
SelectedRequestObservable = this.ObservableForProperty(vm => vm.SelectedRequest).Select(r => r.Value);
}
示例9: PullRequestDetailViewModelDesigner
public PullRequestDetailViewModelDesigner()
{
var repoPath = @"C:\Repo";
Model = new PullRequestModel(419,
"Error handling/bubbling from viewmodels to views to viewhosts",
new AccountDesigner { Login = "shana", IsUser = true },
DateTime.Now.Subtract(TimeSpan.FromDays(3)))
{
State = PullRequestStateEnum.Open,
CommitCount = 9,
};
SourceBranchDisplayName = "shana/error-handling";
TargetBranchDisplayName = "master";
Body = @"Adds a way to surface errors from the view model to the view so that view hosts can get to them.
ViewModels are responsible for handling the UI on the view they control, but they shouldn't be handling UI for things outside of the view. In this case, we're showing errors in VS outside the view, and that should be handled by the section that is hosting the view.
This requires that errors be propagated from the viewmodel to the view and from there to the host via the IView interface, since hosts don't usually know what they're hosting.
![An image](https://cloud.githubusercontent.com/assets/1174461/18882991/5dd35648-8496-11e6-8735-82c3a182e8b4.png)";
var gitHubDir = new PullRequestDirectoryNode("GitHub");
var modelsDir = new PullRequestDirectoryNode("Models");
var repositoriesDir = new PullRequestDirectoryNode("Repositories");
var itrackingBranch = new PullRequestFileNode(repoPath, @"GitHub\Models\ITrackingBranch.cs", PullRequestFileStatus.Modified);
var oldBranchModel = new PullRequestFileNode(repoPath, @"GitHub\Models\OldBranchModel.cs", PullRequestFileStatus.Removed);
var concurrentRepositoryConnection = new PullRequestFileNode(repoPath, @"GitHub\Repositories\ConcurrentRepositoryConnection.cs", PullRequestFileStatus.Added);
repositoriesDir.Files.Add(concurrentRepositoryConnection);
modelsDir.Directories.Add(repositoriesDir);
modelsDir.Files.Add(itrackingBranch);
modelsDir.Files.Add(oldBranchModel);
gitHubDir.Directories.Add(modelsDir);
ChangedFilesTree = new ReactiveList<IPullRequestChangeNode>();
ChangedFilesTree.Add(gitHubDir);
ChangedFilesList = new ReactiveList<IPullRequestFileNode>();
ChangedFilesList.Add(concurrentRepositoryConnection);
ChangedFilesList.Add(itrackingBranch);
ChangedFilesList.Add(oldBranchModel);
}
示例10: DispatchViewModel
public DispatchViewModel(IScreen screen, ISession session)
{
HostScreen = screen;
GoBack = HostScreen.Router.NavigateBack;
Techs = new ReactiveList<Employee>();
Tickets = new ReactiveList<Ticket>();
var getFreshTechs = new ReactiveCommand();
getFreshTechs.ObserveOn(RxApp.MainThreadScheduler).Subscribe(_ =>
{
Techs.Clear();
session.FetchResults<Employee>()
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(x => Techs.Add(x));
});
var getFreshTickets = new ReactiveCommand();
getFreshTickets.ObserveOn(RxApp.MainThreadScheduler).Subscribe(_ =>
{
Tickets.Clear();
session.FetchResults<Ticket>()
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(x => Tickets.Add(x));
});
Refresh = new ReactiveCommand(session.IsWorking.Select(x => !x));
Refresh.Subscribe(_ =>
{
getFreshTechs.Execute(default(object));
getFreshTickets.Execute(default(object));
});
Assign = new ReactiveCommand(Observable.CombineLatest(
this.WhenAny(
x => x.SelectedEmployee,
y => y.SelectedTicket,
(x, y) => x.Value != null && y.Value != null),
Refresh.CanExecuteObservable,
(x, y) => x && y));
Assign.Subscribe(_ =>
{
using (session.ScopedChanges())
{
var eventTaker = session.Take<TicketEvent>();
eventTaker.Add(new TicketEvent { Employee = SelectedEmployee, Ticket = SelectedTicket, TicketStatus = TicketStatus.Assigned, Time = DateTime.Now });
}
});
_error = session.ThrownExceptions
.Select(x => x.Message)
.ObserveOn(RxApp.MainThreadScheduler)
.ToProperty(this, x => x.Error);
Refresh.Execute(default(object));
}
示例11: CollectionCountChangedTest
public void CollectionCountChangedTest()
{
var fixture = new ReactiveList<int>();
var before_output = new List<int>();
var output = new List<int>();
fixture.CountChanging.Subscribe(before_output.Add);
fixture.CountChanged.Subscribe(output.Add);
fixture.Add(10);
fixture.Add(20);
fixture.Add(30);
fixture.RemoveAt(1);
fixture.Clear();
var before_results = new[] { 0, 1, 2, 3, 2 };
Assert.AreEqual(before_results.Length, before_output.Count);
var results = new[] { 1, 2, 3, 2, 0 };
Assert.AreEqual(results.Length, output.Count);
}
示例12: AssignedTicketsViewModel
public AssignedTicketsViewModel(IScreen screen, ISession session)
{
HostScreen = screen;
GoBack = HostScreen.Router.NavigateBack;
Tickets = new ReactiveList<TicketItemViewModel>();
Employees = new ReactiveList<Employee>();
_isFetchingTickets = session.IsWorking
.ToProperty(this, x => x.IsFetchingTickets);
this.WhenAnyValue(x => x.SelectedEmployee)
.Where(x => x != null)
.Subscribe(x =>
{
Tickets.Clear();
session.FetchMergedResults(
QueryHelper.QueryOnTicketsAndEvents,
QueryHelper.Filter<TicketWithEvent>(z =>
(x.Id == int.MinValue || z.EmployeeId == x.Id) &&
z.TicketStatus == TicketStatus.Assigned))
.ObserveOn(RxApp.MainThreadScheduler)
.Select(y => new TicketItemViewModel(y.Description, y.TicketStatus ?? TicketStatus.Open))
.Subscribe(y => Tickets.Add(y));
});
SelectedEmployee = new Employee { Name = "All", TicketEvents = null, Id = int.MinValue };
Employees.Add(SelectedEmployee);
session.FetchResults<Employee>()
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(x => Employees.Add(x));
session.ThrownExceptions.Subscribe(x =>
{
Console.WriteLine(x.Message);
});
}
示例13: MainWindowViewModel
public MainWindowViewModel()
{
Extension = "*.docx";
Folders = @"C:\Test\Test Docs";
Items = new ReactiveList<ResultItem>();
CountCommand = ReactiveCommand.Create();
CountCommand.Subscribe(x => DoCount());
// this is how we can update the viewmodel
// from the actor.
AddItem = new Subject<ResultItem>();
AddItem.ObserveOnDispatcher().Subscribe(item => Items.Add(item));
m_vmActor = AkkaSystem.System.ActorOf(DocumentInspectorSupervisor.GetProps(this), ActorPaths.DocumentInspectorSupervisor.Name);
}
示例14: MainWindowModel
public MainWindowModel()
{
Tweets = new ReactiveList<TweetViewModel>();
LoadTweets = ReactiveCommand.CreateAsyncTask(async _ =>
{
await Task.Delay(2000);
foreach (var t in FakeData.GetFakeTweets())
Tweets.Add(t);
});
var canRemoveTweet = this.WhenAnyValue(vm => vm.Tweets.Count)
.Select(c => c > 0);
RemoveTweet = ReactiveCommand.Create(canRemoveTweet);
RemoveTweet.Subscribe(_ => Tweets.RemoveAt(0));
}
示例15: MainWindowViewModel
public MainWindowViewModel()
{
Extension = "*.txt";
// Folders = @"c:\Users\njimenez\Documents\Projects\CSharp\Games\Poker";
Folders = @"d:\downloads";
Items = new ReactiveList<ResultItem>();
CountCommand = ReactiveCommand.Create();
CountCommand.Subscribe( x => DoCount() );
// this is how we can update the viewmodel
// from the actor.
AddItem = new Subject<ResultItem>();
AddItem.ObserveOnDispatcher().Subscribe( item => Items.Add( item ) );
m_vmActor = AkkaSystem.System.ActorOf( WordCounterSupervisor.GetProps( this ), ActorPaths.WordCounterSupervisorActor.Name );
}