/// <inheritdoc/> protected override SelectorMatch Evaluate(IStyleable control, bool subscribe) { if (TargetType != null) { var controlType = control.StyleKey ?? control.GetType(); if (IsConcreteType) { if (controlType != TargetType) { return(SelectorMatch.False); } } else { if (!TargetType.GetTypeInfo().IsAssignableFrom(controlType.GetTypeInfo())) { return(SelectorMatch.False); } } } if (Name != null && control.Name != Name) { return(SelectorMatch.False); } if (_classes.IsValueCreated && _classes.Value.Count > 0) { if (subscribe) { var observable = Observable.FromEventPattern < NotifyCollectionChangedEventHandler, NotifyCollectionChangedEventArgs>( x => control.Classes.CollectionChanged += x, x => control.Classes.CollectionChanged -= x) .StartWith((EventPattern <NotifyCollectionChangedEventArgs>)null) .Select(_ => Matches(control.Classes)) .DistinctUntilChanged(); return(new SelectorMatch(observable)); } else { return(new SelectorMatch(Matches(control.Classes))); } } else { return(SelectorMatch.True); } }
/// <inheritdoc/> protected override SelectorMatch Evaluate(IStyleable control, bool subscribe) { if (TargetType != null) { var controlType = control.StyleKey ?? control.GetType(); if (IsConcreteType) { if (controlType != TargetType) { return(SelectorMatch.NeverThisType); } } else { if (!TargetType.GetTypeInfo().IsAssignableFrom(controlType.GetTypeInfo())) { return(SelectorMatch.NeverThisType); } } } if (Name != null) { return(control.Name == Name ? SelectorMatch.AlwaysThisInstance : SelectorMatch.NeverThisInstance); } if (_classes.IsValueCreated && _classes.Value.Count > 0) { if (subscribe) { var observable = new ClassObserver(control.Classes, _classes.Value); return(new SelectorMatch(observable)); } else { return(Matches(control.Classes) ? SelectorMatch.AlwaysThisInstance : SelectorMatch.NeverThisInstance); } } else { return(SelectorMatch.AlwaysThisType); } }
protected override SelectorMatch Evaluate(IStyleable control, bool subscribe) { if (TargetType != null) { var controlType = control.StyleKey ?? control.GetType(); if (IsConcreteType) { if (controlType != TargetType) { return(SelectorMatch.NeverThisType); } } else { if (!TargetType.IsAssignableFrom(controlType)) { return(SelectorMatch.NeverThisType); } } } if (Name != null && control.Name != Name) { return(SelectorMatch.NeverThisInstance); } if (_classes.IsValueCreated && _classes.Value.Count > 0) { if (subscribe) { var observable = new StyleClassActivator(control.Classes, _classes.Value); return(new SelectorMatch(observable)); } if (!StyleClassActivator.AreClassesMatching(control.Classes, Classes)) { return(SelectorMatch.NeverThisInstance); } } return(Name == null ? SelectorMatch.AlwaysThisType : SelectorMatch.AlwaysThisInstance); }
private void Bind( IStyleable control, PerspexProperty property, IBinding binding, ISubject <object> subject) { var mode = binding.Mode; if (mode == BindingMode.Default) { mode = property.GetMetadata(control.GetType()).DefaultBindingMode; } control.Bind( property, subject, mode, binding.Priority); }
/// <summary> /// Applies the setter to a control. /// </summary> /// <param name="style">The style that is being applied.</param> /// <param name="control">The control.</param> /// <param name="activator">An optional activator.</param> public IDisposable Apply(IStyle style, IStyleable control, IObservable <bool> activator) { Contract.Requires <ArgumentNullException>(control != null); var description = style?.ToString(); if (Property == null) { throw new InvalidOperationException("Setter.Property must be set."); } var value = Value; var binding = value as IBinding; if (binding == null) { var template = value as ITemplate; bool isPropertyOfTypeITemplate = typeof(ITemplate).GetTypeInfo() .IsAssignableFrom(Property.PropertyType.GetTypeInfo()); if (template != null && !isPropertyOfTypeITemplate) { var materialized = template.Build(); NameScope.SetNameScope((StyledElement)materialized, new NameScope()); value = materialized; } if (activator == null) { return(control.Bind(Property, ObservableEx.SingleValue(value), BindingPriority.Style)); } else { var activated = new ActivatedValue(activator, value, description); return(control.Bind(Property, activated, BindingPriority.StyleTrigger)); } } else { var source = binding.Initiate(control, Property); if (source != null) { var cloned = Clone(source, source.Mode == BindingMode.Default ? Property.GetMetadata(control.GetType()).DefaultBindingMode : source.Mode, style, activator); return(BindingOperations.Apply(control, Property, cloned, null)); } } return(Disposable.Empty); }
private static SelectorMatch MatchOfType(IStyleable control, Type type) { var controlType = control.StyleKey ?? control.GetType(); return(new SelectorMatch(controlType == type)); }
private static SelectorMatch MatchIs(IStyleable control, Type type) { var controlType = control.StyleKey ?? control.GetType(); return(new SelectorMatch(type.GetTypeInfo().IsAssignableFrom(controlType.GetTypeInfo()))); }
private void Bind( IStyleable control, PerspexProperty property, IBinding binding, ISubject<object> subject) { var mode = binding.Mode; if (mode == BindingMode.Default) { mode = property.GetMetadata(control.GetType()).DefaultBindingMode; } control.Bind( property, subject, mode, binding.Priority); }
/// <inheritdoc/> protected override SelectorMatch Evaluate(IStyleable control, bool subscribe) { if (TargetType != null) { var controlType = control.StyleKey ?? control.GetType(); if (IsConcreteType) { if (controlType != TargetType) { return SelectorMatch.False; } } else { if (!TargetType.GetTypeInfo().IsAssignableFrom(controlType.GetTypeInfo())) { return SelectorMatch.False; } } } if (Name != null && control.Name != Name) { return SelectorMatch.False; } if (_classes.IsValueCreated && _classes.Value.Count > 0) { if (subscribe) { var observable = Observable.FromEventPattern< NotifyCollectionChangedEventHandler, NotifyCollectionChangedEventArgs>( x => control.Classes.CollectionChanged += x, x => control.Classes.CollectionChanged -= x) .StartWith((EventPattern<NotifyCollectionChangedEventArgs>)null) .Select(_ => Matches(control.Classes)); return new SelectorMatch(observable); } else { return new SelectorMatch(Matches(control.Classes)); } } else { return SelectorMatch.True; } }