本文整理汇总了C#中ReactiveList.Any方法的典型用法代码示例。如果您正苦于以下问题:C# ReactiveList.Any方法的具体用法?C# ReactiveList.Any怎么用?C# ReactiveList.Any使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReactiveList
的用法示例。
在下文中一共展示了ReactiveList.Any方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
});
}
示例2: IssueLabelsViewModel
public IssueLabelsViewModel(Func<Task<IReadOnlyList<Label>>> loadLabels)
{
var labels = new ReactiveList<Label>();
Selected = new ReactiveList<Label>();
Labels = labels.CreateDerivedCollection(x =>
{
var vm = new IssueLabelItemViewModel(x);
vm.IsSelected = Selected.Any(y => string.Equals(y.Name, x.Name));
// vm.GoToCommand
// .Select(_ => x)
// .Where(y => vm.IsSelected)
// .Where(y => Selected.All(l => l.Url != y.Url))
// .Subscribe(Selected.Add);
// vm.GoToCommand
// .Select(_ => x)
// .Where(y => !vm.IsSelected)
// .Select(y => Selected.Where(l => l.Url == y.Url).ToArray())
// .Subscribe(Selected.RemoveAll);
return vm;
});
SelectLabelsCommand = ReactiveCommand.CreateAsyncTask(t => {
var selectedLabelsUrl = Selected.Select(x => x.Url).ToArray();
var prevSelectedLabelsUrl = _previouslySelectedLabels.Select(x => x.Url).ToArray();
var intersect = selectedLabelsUrl.Intersect(prevSelectedLabelsUrl).ToArray();
var different = selectedLabelsUrl.Length != prevSelectedLabelsUrl.Length || intersect.Length != selectedLabelsUrl.Length;
return Task.FromResult(0); //different ? updateIssue(new ReadOnlyCollection<Label>(Selected)) : Task.FromResult(0);
});
LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
labels.Reset(await loadLabels());
});
}
示例3: SmoothDrawView
public SmoothDrawView(RectangleF frame, UIColor drawingColor, float lineThickness) : base(frame){
paths = new ReactiveList<List<UIBezierPath>> ();
this.BackgroundColor = UIColor.Clear;
strokeColor = drawingColor ?? UIColor.Yellow;
this.lineThickness = lineThickness;
this.MultipleTouchEnabled = false;
undo = new FlatButton(RectangleF.Empty);
undo.Alpha = default(float);
undo.SetTitle ("Undo", UIControlState.Normal);
undo.SetBackgroundColor (MobileCore.Values.Colors.WhiteSeventyFivePercent.ToNative (), UIControlState.Normal);
undo.SetTitleColor (MobileCore.Values.Colors.DarkGray.ToNative (), UIControlState.Normal);
Add (undo);
this.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints ();
this.AddConstraints (
undo.AtBottomOf(this, Constants.Layout.VerticalPadding),
undo.AtRightOf(this, Constants.Layout.HorizontalPadding),
undo.Width().GreaterThanOrEqualTo(56f),
undo.Height().GreaterThanOrEqualTo(32f)
);
Observable.CombineLatest (
this.WhenAnyValue (x => x.Enabled),
paths.CountChanged.StartWith(0),
(enabled, count) => enabled && count > 0)
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe (shouldDisplay => UIView.AnimateAsync(Constants.Animation.StandardAnimationDuration, () => undo.Alpha = shouldDisplay ? 1.0f : default(float) ));
this.WhenAnyValue (vm => vm.Enabled)
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe (enabled => UserInteractionEnabled = enabled);
Observable.FromEventPattern(h => undo.TouchUpInside += h, h => undo.TouchUpInside -= h)
.Where(_ => paths.Any())
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(_ => {
paths.RemoveAt (paths.Count - 1);
this.SetNeedsDisplay ();
});
}
示例4: RepositoryPublishViewModel
public RepositoryPublishViewModel(
IRepositoryHosts hosts,
IRepositoryPublishService repositoryPublishService,
IVSServices vsServices,
IConnectionManager connectionManager)
{
this.vsServices = vsServices;
this.hosts = hosts;
title = this.WhenAny(
x => x.SelectedHost,
x => x.Value != null ?
string.Format(CultureInfo.CurrentCulture, "Publish repository to {0}", x.Value.Title) :
"Publish repository"
)
.ToProperty(this, x => x.Title);
Connections = new ReactiveList<IConnection>(connectionManager.Connections);
this.repositoryPublishService = repositoryPublishService;
if (Connections.Any())
{
SelectedConnection = Connections.FirstOrDefault(x => x.HostAddress.IsGitHubDotCom()) ?? Connections[0];
}
accounts = this.WhenAny(x => x.SelectedConnection, x => x.Value != null ? hosts.LookupHost(x.Value.HostAddress) : RepositoryHosts.DisconnectedRepositoryHost)
.Where(x => !(x is DisconnectedRepositoryHost))
.SelectMany(host => host.ModelService.GetAccounts())
.ObserveOn(RxApp.MainThreadScheduler)
.ToProperty(this, x => x.Accounts, initialValue: new ReadOnlyCollection<IAccount>(new IAccount[] {}));
this.WhenAny(x => x.Accounts, x => x.Value)
.WhereNotNull()
.Where(accts => accts.Any())
.Subscribe(accts => {
var selectedAccount = accts.FirstOrDefault();
if (selectedAccount != null)
{
SelectedAccount = accts.FirstOrDefault();
}
});
isHostComboBoxVisible = this.WhenAny(x => x.Connections, x => x.Value)
.WhereNotNull()
.Select(h => h.Count > 1)
.ToProperty(this, x => x.IsHostComboBoxVisible);
InitializeValidation();
PublishRepository = InitializePublishRepositoryCommand();
canKeepPrivate = CanKeepPrivateObservable.CombineLatest(PublishRepository.IsExecuting,
(canKeep, publishing) => canKeep && !publishing)
.ToProperty(this, x => x.CanKeepPrivate);
isPublishing = PublishRepository.IsExecuting
.ToProperty(this, x => x.IsPublishing);
var defaultRepositoryName = repositoryPublishService.LocalRepositoryName;
if (!string.IsNullOrEmpty(defaultRepositoryName))
{
DefaultRepositoryName = defaultRepositoryName;
}
this.WhenAny(x => x.SelectedConnection, x => x.SelectedAccount,
(a,b) => true)
.Where(x => RepositoryNameValidator.ValidationResult != null && SafeRepositoryNameWarningValidator.ValidationResult != null)
.Subscribe(async _ =>
{
var name = RepositoryName;
RepositoryName = null;
await RepositoryNameValidator.ResetAsync();
await SafeRepositoryNameWarningValidator.ResetAsync();
RepositoryName = name;
});
}
示例5: CreateTicketsViewModel
public CreateTicketsViewModel(ISession session, IScreen screen = null)
{
#region Initialization
HostScreen = screen ?? new DefaultScreen(RxApp.DependencyResolver);
GoBack = HostScreen.Router.NavigateBack;
CurrentBatch = new ReactiveList<TicketItemViewModel>();
Customers = new ReactiveList<Customer>();
#endregion
#region Populate Customer List
session.FetchResults<Customer>()
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(c => Customers.Add(c));
#endregion
#region Wire Up Commands
AddTicket = new ReactiveCommand(
this.WhenAny(
x => x.CurrentBatch,
y => y.Problem,
z => z.SelectedCustomer,
(x, y, z) => x.Value.Count() <= 100 &&
!string.IsNullOrWhiteSpace(y.Value) &&
z.Value != null));
AddTicket.Subscribe(_ =>
{
CurrentBatch.Add(new TicketItemViewModel(Problem, CurrentBatch.Remove));
Problem = default(string);
});
var anyInList = CurrentBatch.Changed.Select(_ => CurrentBatch.Any());
var isCustomerSelected = this.WhenAnyValue(x => x.SelectedCustomer).Select(x => x != null);
var shouldSaveChanges = Observable.CombineLatest(anyInList, isCustomerSelected, (x, y) => x && y);
SaveChanges = new ReactiveCommand(shouldSaveChanges.StartWith(false));
_isExecuting = session.IsWorking.ToProperty(this, x => x.IsExecuting, false);
SaveChanges.Select(x => CurrentBatch.ToList())
.Subscribe(x =>
{
using (INotifyWhenComplete token = session.ScopedChanges())
{
var ticketTaker = session.Take<Ticket>();
token.Completion
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(b => { if (b) (CurrentBatch as IList).Clear(); });
foreach (var item in x)
{
ticketTaker.Add(new Ticket
{
Description = item.Description,
CustomerId = SelectedCustomer.Id
});
}
}
});
#endregion
}