本文整理汇总了C#中ReactiveList.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# ReactiveList.Clear方法的具体用法?C# ReactiveList.Clear怎么用?C# ReactiveList.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReactiveList
的用法示例。
在下文中一共展示了ReactiveList.Clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExploreViewModel
public ExploreViewModel(ISessionService applicationService)
{
ShowRepositoryDescription = applicationService.Account.ShowRepositoryDescriptionInList;
Title = "Explore";
var gotoRepository = new Action<RepositoryItemViewModel>(x => {
var vm = this.CreateViewModel<RepositoryViewModel>();
vm.RepositoryOwner = x.Owner;
vm.RepositoryName = x.Name;
NavigateTo(vm);
});
var repositories = new ReactiveList<Octokit.Repository>();
Repositories = repositories.CreateDerivedCollection(x =>
new RepositoryItemViewModel(x, true, gotoRepository));
var users = new ReactiveList<Octokit.User>();
Users = users.CreateDerivedCollection(x =>
new UserItemViewModel(x.Login, x.AvatarUrl, false, () => {
var vm = this.CreateViewModel<UserViewModel>();
vm.Init(x.Login);
NavigateTo(vm);
}));
this.WhenAnyValue(x => x.SearchFilter)
.DistinctUntilChanged()
.Subscribe(_ => {
SearchText = string.Empty;
users.Clear();
repositories.Clear();
});
var canSearch = this.WhenAnyValue(x => x.SearchText).Select(x => !string.IsNullOrEmpty(x));
SearchCommand = ReactiveCommand.CreateAsyncTask(canSearch, async t => {
try
{
users.Clear();
repositories.Clear();
if (SearchFilter == SearchType.Repositories)
{
var request = new Octokit.SearchRepositoriesRequest(SearchText);
var response = await applicationService.GitHubClient.Search.SearchRepo(request);
repositories.Reset(response.Items);
}
else if (SearchFilter == SearchType.Users)
{
var request = new Octokit.SearchUsersRequest(SearchText);
var response = await applicationService.GitHubClient.Search.SearchUsers(request);
users.Reset(response.Items);
}
}
catch (Exception e)
{
var msg = string.Format("Unable to search for {0}. Please try again.", SearchFilter.Humanize());
throw new Exception(msg, e);
}
});
}
示例2: 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);
}
示例3: 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";
}
示例4: IssueLabelsViewModel
public IssueLabelsViewModel(
Func<Task<IReadOnlyList<Label>>> loadAllLabelsFunc,
Func<Task<IReadOnlyList<Label>>> loadSelectedFunc,
Func<IEnumerable<Label>, Task> saveLabelsFunc)
{
var labels = new ReactiveList<Label>();
var selected = new ReactiveList<Label>();
Labels = labels.CreateDerivedCollection(x =>
{
var vm = new IssueLabelItemViewModel(x);
vm.IsSelected = selected.Any(y => y.Url == x.Url);
return vm;
});
SaveCommand = ReactiveCommand.CreateAsyncTask(_ =>
{
var currentlySelected = Labels.Where(x => x.IsSelected).ToList();
var selectedLabelsUrl = currentlySelected.Select(x => x.Label.Url).ToArray();
var prevSelectedLabelsUrl = selected.Select(x => x.Url).ToArray();
var intersect = selectedLabelsUrl.Intersect(prevSelectedLabelsUrl).ToArray();
var different = selectedLabelsUrl.Length != prevSelectedLabelsUrl.Length || intersect.Length != selectedLabelsUrl.Length;
return different ? saveLabelsFunc(currentlySelected.Select(x => x.Label)) : Task.FromResult(0);
});
LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
selected.Clear();
selected.AddRange((await loadSelectedFunc()) ?? Enumerable.Empty<Label>());
labels.Reset(await loadAllLabelsFunc());
});
}
示例5: BlogViewModel
public BlogViewModel(string title, Uri feedAddress, IFeedService feedService = null, IBlobCache cache = null)
{
Title = title;
FeedAddress = feedAddress;
FeedService = feedService ?? Locator.Current.GetService<IFeedService>();
Cache = cache ?? Locator.Current.GetService<IBlobCache>();
Articles = new ReactiveList<ArticleViewModel>();
Refresh = ReactiveCommand.CreateAsyncObservable(x => GetAndFetchLatestArticles());
Refresh.Subscribe(articles =>
{
// this could be done cleaner, send a PR.
// Refresh.ToPropertyEx(this, x => x.Articles);
Articles.Clear();
Articles.AddRange(articles);
});
Refresh.ThrownExceptions.Subscribe(thrownException => { this.Log().Error(thrownException); });
_isLoading = Refresh.IsExecuting.ToProperty(this, x => x.IsLoading);
// post-condition checks
Condition.Ensures(FeedAddress).IsNotNull();
Condition.Ensures(FeedService).IsNotNull();
Condition.Ensures(Cache).IsNotNull();
}
示例6: 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);
});
}
示例7: 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);
}
});
}
示例8: 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);
}
示例9: 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);
}
示例10: TrackingControlViewModel
public TrackingControlViewModel(ITrackPresenter TrackPresenter, IMappingService MappingService, TrackFormatterManager TrackFormatterManager)
{
_trackPresenter = TrackPresenter;
_trackFormatterManager = TrackFormatterManager;
_mappingService = MappingService;
_track = new ReactiveList<EarthPoint>();
_track.Changed
.Subscribe(_ => RefreshTrack());
LoadTrack = ReactiveCommand.CreateAsyncTask(LoadTrackImpl);
SaveTrack = ReactiveCommand.CreateAsyncTask(SaveTrackImpl);
ReactiveCommand<object> clearCommand = ReactiveCommand.Create(_track.IsEmptyChanged.Select(e => !e));
clearCommand.Subscribe(_ => _track.Clear());
ClearTrack = clearCommand;
IConnectableObservable<TrackPathRider> prp =
_track.Changed
.Select(_ => new TrackPathRider(new GpsTrack(_track.ToList())))
.Publish();
PathRider = prp;
prp.Connect();
_mappingService.Clicks
.Where(c => c.Action == MouseAction.LeftClick)
.Subscribe(c => AppendPointToTrack(c.Point));
_mappingService.Clicks
.Where(c => c.Action == MouseAction.RightClick)
.Subscribe(c => _track.Remove(_track.LastOrDefault()));
}
示例11: 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));
}
示例12: ChannelViewModel
public ChannelViewModel(string token, string teamId, IScreen screen = null)
{
HostScreen = screen ?? Locator.Current.GetService<IScreen>();
Messages = new ReactiveList<Message>();
var client = new HttpClient(NetCache.UserInitiated) {
BaseAddress = new Uri("https://slack.com"),
};
var api = RestService.For<ISlackApi>(client);
LoadChannelToDisplay = ReactiveCommand.CreateAsyncTask(async _ => {
var channelList = await BlobCache.LocalMachine.GetOrFetchObject("channels_" + teamId,
() => api.GetChannels(token),
RxApp.MainThreadScheduler.Now + TimeSpan.FromMinutes(5.0));
// Try to find ReactiveUI, then general, then whatever the first one is
var channel =
channelList.channels.FirstOrDefault(x => x.name.ToLowerInvariant() == "reactiveui") ??
channelList.channels.FirstOrDefault(x => x.name.ToLowerInvariant() == "general") ??
channelList.channels.First();
return channel.id;
});
LoadChannelToDisplay.Subscribe(x => VisibleChannel = x);
LoadMessages = ReactiveCommand.CreateAsyncTask(async _ => {
var channelToLoad = VisibleChannel;
if (channelToLoad == null) {
channelToLoad = await LoadChannelToDisplay.ExecuteAsync();
}
return await api.GetLatestMessages(token, channelToLoad);
});
LoadMessages.Subscribe(xs => {
Messages.Clear();
Messages.AddRange(xs.messages);
});
LoadMessages.ThrownExceptions.Subscribe(ex =>
UserError.Throw("Couldn't load messages for room", ex));
MessageTiles = Messages.CreateDerivedCollection(
x => new MessageTileViewModel(x),
x => !String.IsNullOrWhiteSpace(x.text),
(x, y) => x.Model.date.CompareTo(y.Model.date));
}
示例13: 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);
}
示例14: 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);
});
}
示例15: MainWindowModel
public MainWindowModel()
{
_testDataSource = new TestDataSource();
TestModels = new ReactiveList<TestModel>();
//TODO: Add code that declares a derviced collection which uses `CreateTestViewModelFromTestModel`
// as it's conversion, uses `true` as it's filter and 0 as the ordering function
//TODO: Move the `CreateTestViewModelFromTestModel` function into a lambda
SetUpDataCommand = ReactiveCommand.CreateAsyncTask(_ => _testDataSource.GetTests());
SetUpDataCommand.Subscribe(results =>
{
using (SuppressChangeNotifications())
{
TestModels.Clear();
foreach (var model in results)
TestModels.Add(model);
}
});
}