本文整理汇总了C#中ReactiveList.Where方法的典型用法代码示例。如果您正苦于以下问题:C# ReactiveList.Where方法的具体用法?C# ReactiveList.Where怎么用?C# ReactiveList.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReactiveList
的用法示例。
在下文中一共展示了ReactiveList.Where方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MonthViewModel
public MonthViewModel(IEnumerable<Transfer> transfers)
{
Transfers = new ReactiveList<Transfer>(transfers);
MonthName = Transfers.First().Raw.Date.ToString("MMMM");
this.WhenAnyObservable(x => x.Transfers.Changed)
.Select(_ => Transfers.Where(x => x.Raw.Amount > 0).Sum(x => x.Raw.Amount))
.StartWith(Transfers.Where(x => x.Raw.Amount > 0).Sum(x => x.Raw.Amount))
.ToProperty(this, vm => vm.Incomes, out income);
this.WhenAnyObservable(x => x.Transfers.Changed)
.Select(_ => Transfers.Where(x => x.Raw.Amount < 0).Sum(x => x.Raw.Amount))
.StartWith(Transfers.Where(x => x.Raw.Amount < 0).Sum(x => x.Raw.Amount))
.ToProperty(this, vm => vm.Expanses, out expenditure);
this.WhenAnyValue(x => x.Incomes, x => x.Expanses)
.Select(t => t.Item1 + t.Item2)
.ToProperty(this, vm => vm.Balance, out balance);
}
示例2: MainWindowViewModel
public MainWindowViewModel()
{
ReleasesListHint = "Type in a release location URL or path to files";
ReleasesList = new ReactiveList<ReleaseEntryViewModel>();
ReleasesList.ChangeTrackingEnabled = true;
CheckRemoteUpdateInfo = ReactiveCommand.CreateAsyncTask(
this.WhenAny(x => x.ReleaseLocation, x => !String.IsNullOrWhiteSpace(x.Value)),
async _ => {
ReleasesListHint = "";
var releaseData = default(String);
if (Regex.IsMatch(ReleaseLocation, "^https?://", RegexOptions.IgnoreCase)) {
var wc = new WebClient();
releaseData = await wc.DownloadStringTaskAsync(ReleaseLocation + "/RELEASES");
} else {
releaseData = File.ReadAllText(releaseData, Encoding.UTF8);
}
var ret = releaseData.Split('\n')
.Select(x => ReleaseEntry.ParseReleaseEntry(x))
.ToList();
return ret;
});
CheckRemoteUpdateInfo.ThrownExceptions
.Subscribe(ex => ReleasesListHint = "Failed to check for updates: " + ex.Message);
CheckRemoteUpdateInfo
.Subscribe(x => {
var vms = x
.Where(y => y.IsDelta == false)
.Select(y => new ReleaseEntryViewModel(y));
using (ReleasesList.SuppressChangeNotifications()) {
ReleasesList.Clear();
ReleasesList.AddRange(vms);
}
});
this.WhenAnyValue(x => x.ReleaseLocation)
.Throttle(TimeSpan.FromMilliseconds(750), RxApp.MainThreadScheduler)
.InvokeCommand(CheckRemoteUpdateInfo);
ReleasesList.ItemChanged
.Where(x => x.PropertyName == "CurrentAction")
.Subscribe(x => updateStartsAndEnds(x.Sender));
DoIt = ReactiveCommand.CreateAsyncTask(
this.WhenAny(x => x.ReleasesList.Count, x => x.Value > 0),
async _ => {
var releasesToApply = ReleasesList.Where(x => x.Enabled).ToList();
if (releasesToApply.Count < 1 || releasesToApply.All(x => x.CurrentAction == ReleaseEntryActions.None)) {
await UserError.Throw(new OkUserError("Nothing to do", "At least one release must have the 'Start' action"));
return;
}
var appName = ReleasesList[0].Name;
var rootAppDir = Environment.ExpandEnvironmentVariables("%LocalAppData%\\" + appName);
if (Directory.Exists(rootAppDir)) {
var result = await UserError.Throw(new YesNoUserError(
"App already installed",
String.Format("App '{0}' is already installed, remove it before running install?", appName)));
if (result == RecoveryOptionResult.CancelOperation) {
return;
}
if (result == RecoveryOptionResult.RetryOperation) {
using (var mgr = new UpdateManager(null, appName, Environment.ExpandEnvironmentVariables("%LocalAppData%"))) {
await mgr.FullUninstall();
}
}
}
foreach (var release in releasesToApply) {
release.ReleaseLocation = this.ReleaseLocation;
await release.ApplyThisRelease.ExecuteAsync(null);
}
});
}
示例3: InstalledViewModel
public InstalledViewModel(Guid id, string metaDataSlug, IEnumerable<InstalledItemViewModel> localContent) {
_id = id;
LocalContent = new ReactiveList<InstalledItemViewModel>(localContent) {ChangeTrackingEnabled = true};
LocalContent.ItemChanged
.Where(x => x.PropertyName == "IsEnabled")
.ObserveOnMainThread()
.Subscribe(x => {
if (x.Sender.IsEnabled)
EnabledItems.Add(x.Sender);
else
EnabledItems.Remove(x.Sender);
});
EnabledItems = new ReactiveList<InstalledItemViewModel>(LocalContent.Where(x => x.IsEnabled));
AddContent =
ReactiveCommand.CreateAsyncTask(
async x => await RequestAsync(new OpenWebLink(ViewType.Browse, metaDataSlug)).ConfigureAwait(false));
_uninstallSelected =
ReactiveCommand.CreateAsyncTask(async x => {
var r =
await
Cheat.DialogManager.MessageBoxAsync(
new MessageBoxDialogParams("Are you sure you wish to uninstall the selected mods?",
"Uninstall items?", SixMessageBoxButton.OKCancel)).ConfigureAwait(false);
if (r != SixMessageBoxResult.OK)
return;
await RequestAsync(
new UninstallInstalledItems(id,
LocalContent.Where(x1 => x1.IsEnabled).Select(x2 => x2.Id).ToList()))
.ConfigureAwait(false);
}).DefaultSetup("UninstallSelected");
_playSelected =
ReactiveCommand.CreateAsyncTask(async x => await RequestAsync(
new PlayInstalledItems(id,
LocalContent.Where(x1 => x1.IsEnabled).Select(x2 => x2.Id).ToList()))
.ConfigureAwait(false))
.DefaultSetup("PlaySelected");
_clear =
ReactiveCommand.CreateAsyncTask(async x => await ResetInternal().ConfigureAwait(false))
.DefaultSetup("Reset");
// TODO: This is a tab, and tabs are only active while shown
// but we want to receive these events regardless of being active or not, otherwise we are not uptodate when the user switches to us.
// Or we need to find a different approach!
Listen<LocalContentAdded>()
.Where(x => _id == x.GameId)
.Select(x => x.LocalContent.MapTo<List<InstalledItemViewModel>>())
.ObserveOnMainThread()
.Subscribe(x => LocalContent.AddRange(x));
Listen<UninstallActionCompleted>()
.Where(x => _id == x.Game.Id)
.Select(x => x.UninstallLocalContentAction.Content.Select(u => u.Content.Id).ToArray())
.ObserveOnMainThread()
.Subscribe(
x =>
LocalContent.RemoveAll(
LocalContent.Where(
c => x.Contains(c.Id))
.ToArray()));
/*
this.WhenActivated(d => {
d();
});
*/
}