コード例 #1
0
        /// <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;*/
        }
コード例 #2
0
ファイル: HtmlLabel.cs プロジェクト: gcardinale/flutnet-sdk
        /// <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();
                    }
                }
            }
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
 /// <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);
 }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
        /// <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);
        }
コード例 #7
0
        /// <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);
        }
コード例 #8
0
 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));
     }
 }
コード例 #9
0
 /// <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);
     }
 }
コード例 #10
0
ファイル: Extensions.cs プロジェクト: victm/AvaloniaSLGrid
 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);
     }
 }
コード例 #11
0
        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));
        }
コード例 #12
0
 /// <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);
     }
 }
コード例 #13
0
        /// <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);
        }
コード例 #14
0
        /// <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);
        }
コード例 #15
0
        /// <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));
        }
コード例 #16
0
ファイル: Canvas.cs プロジェクト: mikel785/Perspex
 /// <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);
 }
コード例 #17
0
ファイル: Canvas.cs プロジェクト: mikel785/Perspex
 /// <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);
 }
コード例 #18
0
 public static void SetSelection(AvaloniaObject obj, ISelection value)
 {
     obj.SetValue(SelectionProperty, value);
 }
コード例 #19
0
 public static void SetAlignBottomWithPanel(AvaloniaObject obj, bool value)
 {
     obj.SetValue(AlignBottomWithPanelProperty, value);
 }
コード例 #20
0
 public static void SetName(AvaloniaObject avaloniaObject, string value) =>
 avaloniaObject.SetValue(NameProperty, value);
コード例 #21
0
ファイル: Grid.cs プロジェクト: q306023680/Avalonia
 /// <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);
 }
コード例 #22
0
 public static void SetFoo(AvaloniaObject target, string value) => target.SetValue(FooProperty, value);
コード例 #23
0
ファイル: Grid.cs プロジェクト: CarlSosaDev/Avalonia
 /// <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);
 }
コード例 #24
0
 /// <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);
 }
コード例 #25
0
ファイル: Grid.cs プロジェクト: CarlSosaDev/Avalonia
 /// <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);
 }
コード例 #26
0
ファイル: RendererOptions.cs プロジェクト: Core2D/Core2D
 /// <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);
 }
コード例 #27
0
 /// <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);
 }
コード例 #28
0
ファイル: Canvas.cs プロジェクト: mikel785/Perspex
 /// <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);
 }
コード例 #29
0
ファイル: HtmlLabel.cs プロジェクト: CarlSosaDev/Avalonia
 /// <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();
             }
         }
     }
 }
コード例 #30
0
 public static void SetIsFileDragDropEnabled(AvaloniaObject obj, bool value)
 {
     obj.SetValue(IsFileDragDropEnabledProperty, value);
 }
コード例 #31
0
ファイル: Grid.cs プロジェクト: q306023680/Avalonia
 /// <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);
 }
コード例 #32
0
 public static void SetFileDragDropTarget(AvaloniaObject obj, bool value)
 {
     obj.SetValue(FileDragDropTargetProperty, value);
 }
コード例 #33
0
 public static void SetMenu(AvaloniaObject o, NativeMenu menu) => o.SetValue(MenuProperty, menu);
コード例 #34
0
 public static void SetShowAlternation(AvaloniaObject obj, bool value)
 {
     obj.SetValue(ShowAlternationProperty, value);
 }
コード例 #35
0
 public static void SetHotKey(AvaloniaObject target, KeyGesture value) => target.SetValue(HotKeyProperty, value);
コード例 #36
0
 public static void SetSwitchTrackOffBackground(AvaloniaObject element, SolidColorBrush value)
 {
     element.SetValue(SwitchTrackOffBackgroundProperty, value);
 }
コード例 #37
0
 /// <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);
 }
コード例 #38
0
ファイル: HotkeyManager.cs プロジェクト: CarlSosaDev/Avalonia
 public static void SetHotKey(AvaloniaObject target, KeyGesture value) => target.SetValue(HotKeyProperty, value);