/// <summary> /// Sets the value of the <paramref name="property"/> only if it hasn't been explicitly set. /// </summary> public static bool SetIfDefault <T>(this AvaloniaObject o, AvaloniaProperty property, T value) { var diag = Avalonia.Diagnostics.AvaloniaObjectExtensions.GetDiagnostic(o, property); if (diag.Priority == BindingPriority.Unset) { o.SetValue(property, value); return(true); } return(false); o.SetValue(property, value); return(true); //TODO: Implement in AvaloniaUI /* * if (AvaloniaPropertyHelper.GetValueSource(o, property).BaseValueSource == BaseValueSource.Default) * { * o.SetValue(property, value); * * return true; * } * * return false;*/ }
/// <summary> /// Handle when dependency property value changes to update the underline HtmlContainer with the new value. /// </summary> private static void OnAvaloniaProperty_valueChanged(AvaloniaObject AvaloniaObject, AvaloniaPropertyChangedEventArgs e) { var control = AvaloniaObject as HtmlLabel; if (control != null) { if (e.Property == AutoSizeProperty) { if ((bool)e.NewValue) { AvaloniaObject.SetValue(AutoSizeHeightOnlyProperty, false); control.InvalidateMeasure(); control.InvalidateVisual(); } } else if (e.Property == AutoSizeHeightOnlyProperty) { if ((bool)e.NewValue) { AvaloniaObject.SetValue(AutoSizeProperty, false); control.InvalidateMeasure(); control.InvalidateVisual(); } } } }
/// <summary> /// Gets the <see cref="BehaviorCollection"/> associated with a specified object. /// </summary> /// <param name="obj">The <see cref="AvaloniaObject"/> 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(AvaloniaObject obj) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } 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> /// Sets the <see cref="BehaviorCollection"/> associated with a specified object. /// </summary> /// <param name="obj">The <see cref="AvaloniaObject"/> on which to set the <see cref="BehaviorCollection"/>.</param> /// <param name="value">The <see cref="BehaviorCollection"/> associated with the object.</param> public static void SetBehaviors(AvaloniaObject obj, BehaviorCollection?value) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } obj.SetValue(BehaviorsProperty, value); }
/// <summary> /// Sets the <see cref="RegionNameProperty"/> attached property. /// </summary> /// <param name="regionTarget">The object to adapt. This is typically a container (i.e a control).</param> /// <param name="regionName">The name of the region to register.</param> public static void SetRegionName(AvaloniaObject regionTarget, string regionName) { if (regionTarget == null) { throw new ArgumentNullException(nameof(regionTarget)); } regionTarget.SetValue(RegionNameProperty, regionName); }
/// <summary> /// Sets the ClearChildViews attached property in a DependencyObject. /// </summary> /// <param name="target">The object in which to set the value.</param> /// <param name="value">The value of to set in the target object's ClearChildViews attached property.</param> public static void SetClearChildViews(AvaloniaObject target, bool value) { if (target == null) { throw new ArgumentNullException(nameof(target)); } target.SetValue(ClearChildViewsRegionBehavior.ClearChildViewsProperty, value); }
/// <summary> /// Sets the <see cref="RegionContextProperty"/> attached property. /// </summary> /// <param name="target">The target element.</param> /// <param name="value">The value.</param> public static void SetRegionContext(AvaloniaObject target, object value) { if (target == null) { throw new ArgumentNullException(nameof(target)); } target.SetValue(RegionContextProperty, value); }
internal static void SyncColumnProperty <T>(AvaloniaObject column, AvaloniaObject content, AvaloniaProperty <T> contentProperty, AvaloniaProperty <T> columnProperty) { if (!column.IsSet(columnProperty)) { content.ClearValue(contentProperty); } else { content.SetValue(contentProperty, column.GetValue(columnProperty)); } }
/// <remarks> /// This method reflects Grid.SharedScopeProperty state by setting / clearing /// dynamic property PrivateSharedSizeScopeProperty. Value of PrivateSharedSizeScopeProperty /// is a collection of SharedSizeState objects for the scope. /// </remarks> internal static void OnIsSharedSizeScopePropertyChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e) { if ((bool)e.NewValue) { SharedSizeScope sharedStatesCollection = new SharedSizeScope(); d.SetValue(PrivateSharedSizeScopeProperty, sharedStatesCollection); } else { d.ClearValue(PrivateSharedSizeScopeProperty); } }
public static void SetValueNoCallback(this AvaloniaObject obj, AvaloniaProperty property, object value) { obj.SuspendHandler(property, true); try { obj.SetValue(property, value); } finally { obj.SuspendHandler(property, false); } }
public static object UpdateDependencyColor(this AvaloniaObject depo, AvaloniaProperty dp, Color newColor) { if (!newColor.IsDefault) { depo.SetValue(dp, newColor.ToBrush()); } else { depo.ClearValue(dp); } return(depo.GetValue(dp)); }
/// <summary> /// <see cref="PropertyMetadata.PropertyChangedCallback"/> /// </summary> /// <remarks> /// This method reflects Grid.SharedScopeProperty state by setting / clearing /// dynamic property PrivateSharedSizeScopeProperty. Value of PrivateSharedSizeScopeProperty /// is a collection of SharedSizeState objects for the scope. /// Also PrivateSharedSizeScopeProperty is FrameworkPropertyMetadataOptions.Inherits property. So that all children /// elements belonging to a certain scope can easily access SharedSizeState collection. As well /// as been norified about enter / exit a scope. /// </remarks> internal static void OnIsSharedSizeScopePropertyChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e) { // is it possible to optimize here something like this: // if ((bool)d.GetValue(Grid.IsSharedSizeScopeProperty) == (d.GetLocalValue(PrivateSharedSizeScopeProperty) != null) // { /* do nothing */ } if ((bool)e.NewValue) { SharedSizeScope sharedStatesCollection = new SharedSizeScope(); d.SetValue(PrivateSharedSizeScopeProperty, sharedStatesCollection); } else { d.ClearValue(PrivateSharedSizeScopeProperty); } }
/// <summary> /// Returns an <see cref="ObservableObject{T}"/> wrapper that can hold an <see cref="IRegion"/>. Using this wrapper /// you can detect when an <see cref="IRegion"/> has been created by the <see cref="RegionAdapterBase{T}"/>. /// /// If the <see cref="ObservableObject{T}"/> wrapper does not yet exist, a new wrapper will be created. When the region /// gets created and assigned to the wrapper, you can use the <see cref="ObservableObject{T}.PropertyChanged"/> event /// to get notified of that change. /// </summary> /// <param name="view">The view that will host the region. </param> /// <returns>Wrapper that can hold an <see cref="IRegion"/> value and can notify when the <see cref="IRegion"/> value changes. </returns> public static ObservableObject <IRegion> GetObservableRegion(AvaloniaObject view) { if (view == null) { throw new ArgumentNullException(nameof(view)); } ObservableObject <IRegion> regionWrapper = view.GetValue(ObservableRegionProperty) as ObservableObject <IRegion>; if (regionWrapper == null) { regionWrapper = new ObservableObject <IRegion>(); view.SetValue(ObservableRegionProperty, regionWrapper); } return(regionWrapper); }
/// <summary> /// Returns an <see cref="ObservableObject{T}"/> wrapper around the RegionContext value. The RegionContext /// will be set on any views (dependency objects) that are inside the <see cref="IRegion.Views"/> collection by /// the <see cref="Behaviors.BindRegionContextToAvaloniaObjectBehavior"/> Behavior. /// The RegionContext will also be set to the control that hosts the Region, by the <see cref="Behaviors.SyncRegionContextWithHostBehavior"/> Behavior. /// /// If the <see cref="ObservableObject{T}"/> wrapper does not already exist, an empty one will be created. This way, an observer can /// notify when the value is set for the first time. /// </summary> /// <param name="view">Any view that hold the RegionContext value. </param> /// <returns>Wrapper around the Regioncontext value. </returns> public static ObservableObject <object> GetObservableContext(AvaloniaObject view) { if (view == null) { throw new ArgumentNullException(nameof(view)); } ObservableObject <object> context = view.GetValue(ObservableRegionContextProperty) as ObservableObject <object>; if (context == null) { context = new ObservableObject <object>(); view.SetValue(ObservableRegionContextProperty, context); } return(context); }
/// <summary> /// Sets the value of a dependency property on <paramref name="targetObject"/> using a markup extension. /// </summary> /// <remarks>This method does not support markup extensions like x:Static that depend on /// having a XAML file as context.</remarks> public static void SetValueToExtension(this AvaloniaObject targetObject, AvaloniaProperty property, MarkupExtension markupExtension) { // This method was copied from ICSharpCode.Core.Presentation (with permission to switch license to X11) if (targetObject == null) { throw new ArgumentNullException(nameof(targetObject)); } if (property == null) { throw new ArgumentNullException(nameof(property)); } if (markupExtension == null) { throw new ArgumentNullException(nameof(markupExtension)); } var serviceProvider = new SetValueToExtensionServiceProvider(targetObject, property); targetObject.SetValue(property, markupExtension.ProvideValue(serviceProvider)); }
/// <summary> /// Sets the value of the Left attached property for a control. /// </summary> /// <param name="element">The control.</param> /// <param name="value">The left value.</param> public static void SetLeft(AvaloniaObject element, double value) { element.SetValue(LeftProperty, value); }
/// <summary> /// Sets the value of the Top attached property for a control. /// </summary> /// <param name="element">The control.</param> /// <param name="value">The top value.</param> public static void SetTop(AvaloniaObject element, double value) { element.SetValue(TopProperty, value); }
public static void SetSelection(AvaloniaObject obj, ISelection value) { obj.SetValue(SelectionProperty, value); }
public static void SetAlignBottomWithPanel(AvaloniaObject obj, bool value) { obj.SetValue(AlignBottomWithPanelProperty, value); }
public static void SetName(AvaloniaObject avaloniaObject, string value) => avaloniaObject.SetValue(NameProperty, value);
/// <summary> /// Sets the value of the RowSpan attached property for a control. /// </summary> /// <param name="element">The control.</param> /// <param name="value">The row span value.</param> public static void SetRowSpan(AvaloniaObject element, int value) { element.SetValue(RowSpanProperty, value); }
public static void SetFoo(AvaloniaObject target, string value) => target.SetValue(FooProperty, value);
/// <summary> /// Sets the value of the Column attached property for a control. /// </summary> /// <param name="element">The control.</param> /// <param name="value">The column value.</param> public static void SetColumn(AvaloniaObject element, int value) { element.SetValue(ColumnProperty, value); }
/// <summary> /// Sets renderer attached property. /// </summary> /// <param name="obj">The avalonia object.</param> /// <param name="value">The shape render value.</param> public static void SetRenderer(AvaloniaObject obj, IShapeRenderer value) { obj.SetValue(RendererProperty, value); }
/// <summary> /// Sets the value of the RowSpan attached property for a control. /// </summary> /// <param name="element">The control.</param> /// <param name="value">The row span value.</param> public static void SetRowSpan(AvaloniaObject element, int value) { element.SetValue(RowSpanProperty, value); }
/// <summary> /// Sets renderer options attached property. /// </summary> /// <param name="obj">The avalonia object.</param> /// <param name="value">The shape render value.</param> public static void SetRenderer(AvaloniaObject obj, ShapeRenderer value) { obj.SetValue(RendererProperty, value); }
/// <summary> /// Sets the value of the BitmapInterpolationMode attached property for a control. /// </summary> /// <param name="element">The control.</param> /// <param name="value">The left value.</param> public static void SetBitmapInterpolationMode(AvaloniaObject element, BitmapInterpolationMode value) { element.SetValue(BitmapInterpolationModeProperty, value); }
/// <summary> /// Sets the value of the Bottom attached property for a control. /// </summary> /// <param name="element">The control.</param> /// <param name="value">The bottom value.</param> public static void SetBottom(AvaloniaObject element, double value) { element.SetValue(BottomProperty, value); }
/// <summary> /// Handle when dependency property value changes to update the underline HtmlContainer with the new value. /// </summary> private static void OnAvaloniaProperty_valueChanged(AvaloniaObject AvaloniaObject, AvaloniaPropertyChangedEventArgs e) { var control = AvaloniaObject as HtmlLabel; if (control != null) { if (e.Property == AutoSizeProperty) { if ((bool)e.NewValue) { AvaloniaObject.SetValue(AutoSizeHeightOnlyProperty, false); control.InvalidateMeasure(); control.InvalidateVisual(); } } else if (e.Property == AutoSizeHeightOnlyProperty) { if ((bool)e.NewValue) { AvaloniaObject.SetValue(AutoSizeProperty, false); control.InvalidateMeasure(); control.InvalidateVisual(); } } } }
public static void SetIsFileDragDropEnabled(AvaloniaObject obj, bool value) { obj.SetValue(IsFileDragDropEnabledProperty, value); }
/// <summary> /// Sets the value of the Column attached property for a control. /// </summary> /// <param name="element">The control.</param> /// <param name="value">The column value.</param> public static void SetColumn(AvaloniaObject element, int value) { element.SetValue(ColumnProperty, value); }
public static void SetFileDragDropTarget(AvaloniaObject obj, bool value) { obj.SetValue(FileDragDropTargetProperty, value); }
public static void SetMenu(AvaloniaObject o, NativeMenu menu) => o.SetValue(MenuProperty, menu);
public static void SetShowAlternation(AvaloniaObject obj, bool value) { obj.SetValue(ShowAlternationProperty, value); }
public static void SetHotKey(AvaloniaObject target, KeyGesture value) => target.SetValue(HotKeyProperty, value);
public static void SetSwitchTrackOffBackground(AvaloniaObject element, SolidColorBrush value) { element.SetValue(SwitchTrackOffBackgroundProperty, value); }
/// <summary> /// Sets data flow attached property. /// </summary> /// <param name="obj">The avalonia object.</param> /// <param name="value">The data flow value.</param> public static void SetDataFlow(AvaloniaObject obj, IDataFlow value) { obj.SetValue(DataFlowProperty, value); }
public static void SetHotKey(AvaloniaObject target, KeyGesture value) => target.SetValue(HotKeyProperty, value);