static void OnSearchTermChanged(IAvaloniaObject o, bool changed) { if (changed) { ((SearchPane)o).StartSearch(o.GetValue(SearchTermProperty)); } }
private static void RefreshBinding(IAvaloniaObject target, AvaloniaProperty property) { if (target.GetValue(property) is IBinding binding) { target.Bind(property, binding); } }
/// <summary> /// Gets the <see cref="BehaviorCollection"/> associated with a specified object. /// </summary> /// <param name="obj">The <see cref="IAvaloniaObject"/> from which to retrieve the <see cref="BehaviorCollection"/>.</param> /// <returns>A <see cref="BehaviorCollection"/> containing the behaviors associated with the specified object.</returns> public static BehaviorCollection?GetBehaviors(IAvaloniaObject obj) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } BehaviorCollection?behaviorCollection = (BehaviorCollection?)obj.GetValue(BehaviorsProperty); if (behaviorCollection == null) { behaviorCollection = new BehaviorCollection(); obj.SetValue(BehaviorsProperty, behaviorCollection); if (obj is Control control) { control.AttachedToVisualTree -= Control_Loaded; control.AttachedToVisualTree += Control_Loaded; control.DetachedFromVisualTree -= Control_Unloaded; control.DetachedFromVisualTree += Control_Unloaded; } } return(behaviorCollection); }
/// <summary> /// Gets an observable for a <see cref="AvaloniaProperty"/>. /// </summary> /// <param name="o">The object.</param> /// <param name="property">The property.</param> /// <returns> /// An observable which fires immediately with the current value of the property on the /// object and subsequently each time the property value changes. /// </returns> public static IObservable <object> GetObservable(this IAvaloniaObject o, AvaloniaProperty property) { Contract.Requires <ArgumentNullException>(o != null); Contract.Requires <ArgumentNullException>(property != null); return(new AvaloniaObservable <object>( observer => { EventHandler <AvaloniaPropertyChangedEventArgs> handler = (s, e) => { if (e.Property == property) { observer.OnNext(e.NewValue); } }; observer.OnNext(o.GetValue(property)); o.PropertyChanged += handler; return Disposable.Create(() => { o.PropertyChanged -= handler; }); }, GetDescription(o, property))); }
protected ExpressionObserver CreateDataContextObserver( IAvaloniaObject target, ExpressionNode node, bool targetIsDataContext, object?anchor) { _ = target ?? throw new ArgumentNullException(nameof(target)); if (!(target is IDataContextProvider)) { target = anchor as IDataContextProvider ?? throw new InvalidOperationException("Cannot find a DataContext to bind to."); } if (!targetIsDataContext) { var result = new ExpressionObserver( () => target.GetValue(StyledElement.DataContextProperty), node, new UpdateSignal(target, StyledElement.DataContextProperty), null); return(result); } else { return(new ExpressionObserver( GetParentDataContext(target), node, null)); } }
/// <summary> /// Gets the value for the RegionName attached property. /// </summary> /// <param name="element">The object to adapt. This is typically a container (i.e a control).</param> /// <returns>The name of the region that should be created when /// the RegionManager is also set in this element.</returns> public string GetRegionName(IAvaloniaObject element) { if (element == null) { throw new ArgumentNullException(nameof(element)); } return(element.GetValue(RegionManager.RegionNameProperty) as string); }
/// <summary> /// Gets the value of the RegionName attached property. /// </summary> /// <param name="element">The target element.</param> /// <returns>The <see cref="IRegionManager"/> attached to the <paramref name="element"/> element.</returns> public IRegionManager GetRegionManager(IAvaloniaObject element) { if (element == null) { throw new ArgumentNullException(nameof(element)); } return(element.GetValue(RegionManager.RegionManagerProperty) as IRegionManager); }
/// <summary> /// Gets the value of the <see cref="RegionNameProperty"/> attached property. /// </summary> /// <param name="target">The target element.</param> /// <returns>The <see cref="IRegionManager"/> attached to the <paramref name="target"/> element.</returns> public static IRegionManager GetRegionManager(IAvaloniaObject target) { if (target == null) { throw new ArgumentNullException(nameof(target)); } return((IRegionManager)target.GetValue(RegionManagerProperty)); }
/// <summary> /// Gets the default value for a property. /// </summary> /// <param name="property">The property.</param> /// <returns>The default value.</returns> private object GetDefaultValue(AvaloniaProperty property) { if (property.Inherits && _inheritanceParent != null) { return(_inheritanceParent.GetValue(property)); } else { return(((IStyledPropertyAccessor)property).GetDefaultValue(GetType())); } }
protected ExpressionObserver CreateTemplatedParentObserver( IAvaloniaObject target, ExpressionNode node) { Contract.Requires <ArgumentNullException>(target != null); var result = new ExpressionObserver( () => target.GetValue(StyledElement.TemplatedParentProperty), node, new UpdateSignal(target, StyledElement.TemplatedParentProperty), null); return(result); }
protected ExpressionObserver CreateTemplatedParentObserver( IAvaloniaObject target, ExpressionNode node) { _ = target ?? throw new ArgumentNullException(nameof(target)); var result = new ExpressionObserver( () => target.GetValue(StyledElement.TemplatedParentProperty), node, new UpdateSignal(target, StyledElement.TemplatedParentProperty), null); return(result); }
private ExpressionObserver CreateTemplatedParentObserver( IAvaloniaObject target, string path, bool enableDataValidation) { Contract.Requires <ArgumentNullException>(target != null); var result = new ExpressionObserver( () => target.GetValue(StyledElement.TemplatedParentProperty), path, new UpdateSignal(target, StyledElement.TemplatedParentProperty), enableDataValidation); return(result); }
private ExpressionObserver CreateTemplatedParentObserver( IAvaloniaObject target, string path) { Contract.Requires <ArgumentNullException>(target != null); var update = target.GetObservable(Control.TemplatedParentProperty) .Skip(1) .Select(_ => Unit.Default); var result = new ExpressionObserver( () => target.GetValue(Control.TemplatedParentProperty), path, update); return(result); }
/// <summary> /// Called for each inherited property when the <see cref="InheritanceParent"/> changes. /// </summary> /// <typeparam name="T">The type of the property value.</typeparam> /// <param name="property">The property.</param> /// <param name="oldParent">The old inheritance parent.</param> internal void InheritanceParentChanged <T>( StyledPropertyBase <T> property, IAvaloniaObject oldParent) { var oldValue = oldParent switch { AvaloniaObject o => o.GetValueOrInheritedOrDefault(property), null => property.GetDefaultValue(GetType()), _ => oldParent.GetValue(property) }; var newValue = GetInheritedOrDefault(property); if (!EqualityComparer <T> .Default.Equals(oldValue, newValue)) { RaisePropertyChanged(property, oldValue, newValue); } }
private ExpressionObserver CreateDataContexObserver( IAvaloniaObject target, string path, bool targetIsDataContext, object anchor) { Contract.Requires <ArgumentNullException>(target != null); if (!(target is IControl)) { target = anchor as IControl; if (target == null) { throw new InvalidOperationException("Cannot find a DataContext to bind to."); } } if (!targetIsDataContext) { var update = target.GetObservable(Control.DataContextProperty) .Skip(1) .Select(_ => Unit.Default); var result = new ExpressionObserver( () => target.GetValue(Control.DataContextProperty), path, update, EnableValidation); return(result); } else { return(new ExpressionObserver( target.GetObservable(Visual.VisualParentProperty) .OfType <IAvaloniaObject>() .Select(x => x.GetObservable(Control.DataContextProperty)) .Switch(), path, EnableValidation)); } }
private ExpressionObserver CreateDataContextObserver( IAvaloniaObject target, string path, bool targetIsDataContext, object anchor, bool enableDataValidation) { Contract.Requires <ArgumentNullException>(target != null); if (!(target is IStyledElement)) { target = anchor as IStyledElement; if (target == null) { throw new InvalidOperationException("Cannot find a DataContext to bind to."); } } if (!targetIsDataContext) { var update = target.GetObservable(StyledElement.DataContextProperty) .Skip(1) .Select(_ => Unit.Default); var result = new ExpressionObserver( () => target.GetValue(StyledElement.DataContextProperty), path, update, enableDataValidation); return(result); } else { return(new ExpressionObserver( GetParentDataContext(target), path, enableDataValidation)); } }
private ExpressionObserver CreateDataContextObserver( IAvaloniaObject target, string path, bool targetIsDataContext, object anchor, bool enableDataValidation) { Contract.Requires <ArgumentNullException>(target != null); if (!(target is IStyledElement)) { target = anchor as IStyledElement; if (target == null) { throw new InvalidOperationException("Cannot find a DataContext to bind to."); } } if (!targetIsDataContext) { var result = ExpressionObserverBuilder.Build( () => target.GetValue(StyledElement.DataContextProperty), path, new UpdateSignal(target, StyledElement.DataContextProperty), enableDataValidation, typeResolver: TypeResolver); return(result); } else { return(ExpressionObserverBuilder.Build( GetParentDataContext(target), path, enableDataValidation, typeResolver: TypeResolver)); } }
private ExpressionObserver CreateDataContextObserver( IAvaloniaObject target, ExpressionNode node, bool targetIsDataContext, object anchor) { Contract.Requires <ArgumentNullException>(target != null); if (!(target is IStyledElement)) { target = anchor as IStyledElement; if (target == null) { throw new InvalidOperationException("Cannot find a DataContext to bind to."); } } if (!targetIsDataContext) { var result = new ExpressionObserver( () => target.GetValue(StyledElement.DataContextProperty), node, new UpdateSignal(target, StyledElement.DataContextProperty), null); return(result); } else { return(new ExpressionObserver( GetParentDataContext(target), node, null)); } }
private ExpressionObserver CreateDataContexObserver( IAvaloniaObject target, string path, bool targetIsDataContext, object anchor) { Contract.Requires<ArgumentNullException>(target != null); if (!(target is IControl)) { target = anchor as IControl; if (target == null) { throw new InvalidOperationException("Cannot find a DataContext to bind to."); } } if (!targetIsDataContext) { var update = target.GetObservable(Control.DataContextProperty) .Skip(1) .Select(_ => Unit.Default); var result = new ExpressionObserver( () => target.GetValue(Control.DataContextProperty), path, update, EnableValidation); return result; } else { return new ExpressionObserver( target.GetObservable(Visual.VisualParentProperty) .OfType<IAvaloniaObject>() .Select(x => x.GetObservable(Control.DataContextProperty)) .Switch(), path, EnableValidation); } }
/*static BorderPresence() * { * Layoutable.AffectsMeasure<Control>(BorderPresenceProperty); * }*/ public static BorderPresence GetBorderPresence(IAvaloniaObject obj) { return(obj.GetValue(BorderPresenceProperty)); }
/// <inheritdoc/> internal override object?RouteGetValue(IAvaloniaObject o) { return(o.GetValue <TValue>(this)); }
public static bool GetAutoWireViewModel(IAvaloniaObject obj) { return((bool)obj.GetValue(AutoWireViewModelProperty)); }
public static string GetSyntaxExtension(IAvaloniaObject obj) { return(obj.GetValue(SyntaxExtensionProperty)); }
public static ObservableCollection <DatabaseColumnHeaderViewModel> GetColumnsWithHeader(IAvaloniaObject obj) { return(obj.GetValue(ColumnsWithHeaderProperty)); }
public static bool GetIsDropTarget(IAvaloniaObject obj) { return((bool)obj.GetValue(IsDropTargetProperty)); }
public static bool GetIsDragSource(IAvaloniaObject obj) { return((bool)obj.GetValue(IsDragSourceProperty)); }
private ExpressionObserver CreateTemplatedParentObserver( IAvaloniaObject target, string path) { Contract.Requires<ArgumentNullException>(target != null); var update = target.GetObservable(Control.TemplatedParentProperty) .Skip(1) .Select(_ => Unit.Default); var result = new ExpressionObserver( () => target.GetValue(Control.TemplatedParentProperty), path, update); return result; }
public static object GetIcon(IAvaloniaObject obj) { return(obj.GetValue(IconProperty)); }
public static double GetIconGap(IAvaloniaObject obj) { return(obj.GetValue(IconGapProperty)); }
public static CornerCurves GetCornerCurves(IAvaloniaObject obj) { return(obj.GetValue(CornerCurvesProperty)); }
public static IDropTarget?GetDropHandler(IAvaloniaObject obj) { return((IDropTarget?)obj.GetValue(DropHandlerProperty)); }
internal override object?RouteGetBaseValue(IAvaloniaObject o, BindingPriority maxPriority) { return(o.GetValue <TValue>(this)); }