/// <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> /// Initializes a new instance of the <see cref="AvaloniaPropertyChangedEventArgs"/> class. /// </summary> /// <param name="sender">The object that the property changed on.</param> /// <param name="property">The property that changed.</param> /// <param name="oldValue">The old value of the property.</param> /// <param name="newValue">The new value of the property.</param> /// <param name="priority">The priority of the binding that produced the value.</param> public AvaloniaPropertyChangedEventArgs( AvaloniaObject sender, AvaloniaProperty property, object oldValue, object newValue, BindingPriority priority) { Sender = sender; Property = property; OldValue = oldValue; NewValue = newValue; Priority = priority; }
public PropertyDetails(AvaloniaObject o, AvaloniaProperty property) { Name = property.IsAttached ? $"[{property.OwnerType.Name}.{property.Name}]" : property.Name; IsAttached = property.IsAttached; // TODO: Unsubscribe when view model is deactivated. o.GetObservable(property).Subscribe(x => { var diagnostic = o.GetDiagnostic(property); Value = diagnostic.Value ?? "(null)"; Priority = (diagnostic.Priority != BindingPriority.Unset) ? diagnostic.Priority.ToString() : diagnostic.Property.Inherits ? "Inherited" : "Unset"; Diagnostic = diagnostic.Diagnostic; }); }
/// <summary> /// tries to set the AssociatedObject /// </summary> /// <param name="avaloniaObject"></param> public void Attach(AvaloniaObject avaloniaObject) { if (avaloniaObject != this.AssociatedObject) { if (this.AssociatedObject != null) { throw new InvalidOperationException("Associated Object already set."); } // Ensure the type constraint is met if (avaloniaObject != null && !this.AssociatedObjectTypeConstraint.IsAssignableFrom(avaloniaObject.GetType())) { throw new InvalidOperationException($"Cannot assign {this.GetType().Name} {avaloniaObject.GetType().Name} {this.AssociatedObjectTypeConstraint.Name}"); } this.associatedObject = avaloniaObject; this.OnAttached(); } }
public AvaloniaXamlIlWellKnownTypes(XamlIlAstTransformationContext ctx) { XamlIlTypes = ctx.Configuration.WellKnownTypes; AvaloniaObject = ctx.Configuration.TypeSystem.GetType("Avalonia.AvaloniaObject"); IAvaloniaObject = ctx.Configuration.TypeSystem.GetType("Avalonia.IAvaloniaObject"); AvaloniaObjectExtensions = ctx.Configuration.TypeSystem.GetType("Avalonia.AvaloniaObjectExtensions"); AvaloniaProperty = ctx.Configuration.TypeSystem.GetType("Avalonia.AvaloniaProperty"); BindingPriority = ctx.Configuration.TypeSystem.GetType("Avalonia.Data.BindingPriority"); IBinding = ctx.Configuration.TypeSystem.GetType("Avalonia.Data.IBinding"); IDisposable = ctx.Configuration.TypeSystem.GetType("System.IDisposable"); Transitions = ctx.Configuration.TypeSystem.GetType("Avalonia.Animation.Transitions"); AssignBindingAttribute = ctx.Configuration.TypeSystem.GetType("Avalonia.Data.AssignBindingAttribute"); AvaloniaObjectBindMethod = AvaloniaObjectExtensions.FindMethod("Bind", IDisposable, false, IAvaloniaObject, AvaloniaProperty, IBinding, ctx.Configuration.WellKnownTypes.Object); UnsetValueType = ctx.Configuration.TypeSystem.GetType("Avalonia.UnsetValueType"); AvaloniaObjectSetValueMethod = AvaloniaObject.FindMethod("SetValue", XamlIlTypes.Void, false, AvaloniaProperty, XamlIlTypes.Object, BindingPriority); }
private IEnumerable <(AvaloniaProperty, object)> CollectChangedValue(AvaloniaObject obj, IEnumerable <AvaloniaProperty> aprops) { foreach (var aprop in aprops) { if (aprop.Name == "Parent") { continue; } if (aprop.IsReadOnly) { continue; } if (obj.IsSet(aprop)) { var objValue = obj.GetValue(aprop); yield return(aprop, objValue); } } }
public PropertyDetails(AvaloniaObject o, AvaloniaProperty property) { Name = property.IsAttached ? $"[{property.OwnerType.Name}.{property.Name}]" : property.Name; IsAttached = property.IsAttached; // TODO: Unsubscribe when view model is deactivated. o.GetObservable(property).Subscribe(x => { var diagnostic = o.GetDiagnostic(property); Value = diagnostic.Value ?? "(null)"; Priority = (diagnostic.Priority != BindingPriority.Unset) ? diagnostic.Priority.ToString() : diagnostic.Property.Inherits ? "Inherited" : "Unset"; Diagnostic = diagnostic.Diagnostic; }); }
/// <summary> /// Method that will create the region, by calling the right <see cref="IRegionAdapter"/>. /// </summary> /// <param name="targetElement">The target element that will host the <see cref="IRegion"/>.</param> /// <param name="regionName">Name of the region.</param> /// <returns>The created <see cref="IRegion"/></returns> protected virtual IRegion CreateRegion(AvaloniaObject targetElement, string regionName) { if (targetElement == null) { throw new ArgumentNullException(nameof(targetElement)); } try { // Build the region IRegionAdapter regionAdapter = this.regionAdapterMappings.GetMapping(targetElement.GetType()); IRegion region = regionAdapter.Initialize(targetElement, regionName); return(region); } catch (Exception ex) { throw new RegionCreationException(string.Format(CultureInfo.CurrentCulture, Resources.RegionCreationException, regionName, ex), ex); } }
public AvaloniaXamlIlWellKnownTypes(XamlIlAstTransformationContext ctx) { XamlIlTypes = ctx.Configuration.WellKnownTypes; XamlIlMappings = ctx.Configuration.TypeMappings; AvaloniaObject = ctx.Configuration.TypeSystem.GetType("Avalonia.AvaloniaObject"); IAvaloniaObject = ctx.Configuration.TypeSystem.GetType("Avalonia.IAvaloniaObject"); AvaloniaObjectExtensions = ctx.Configuration.TypeSystem.GetType("Avalonia.AvaloniaObjectExtensions"); AvaloniaProperty = ctx.Configuration.TypeSystem.GetType("Avalonia.AvaloniaProperty"); AvaloniaPropertyT = ctx.Configuration.TypeSystem.GetType("Avalonia.AvaloniaProperty`1"); BindingPriority = ctx.Configuration.TypeSystem.GetType("Avalonia.Data.BindingPriority"); IBinding = ctx.Configuration.TypeSystem.GetType("Avalonia.Data.IBinding"); IDisposable = ctx.Configuration.TypeSystem.GetType("System.IDisposable"); Transitions = ctx.Configuration.TypeSystem.GetType("Avalonia.Animation.Transitions"); AssignBindingAttribute = ctx.Configuration.TypeSystem.GetType("Avalonia.Data.AssignBindingAttribute"); AvaloniaObjectBindMethod = AvaloniaObjectExtensions.FindMethod("Bind", IDisposable, false, IAvaloniaObject, AvaloniaProperty, IBinding, ctx.Configuration.WellKnownTypes.Object); UnsetValueType = ctx.Configuration.TypeSystem.GetType("Avalonia.UnsetValueType"); StyledElement = ctx.Configuration.TypeSystem.GetType("Avalonia.StyledElement"); INameScope = ctx.Configuration.TypeSystem.GetType("Avalonia.Controls.INameScope"); INameScopeRegister = INameScope.GetMethod( new FindMethodMethodSignature("Register", XamlIlTypes.Void, XamlIlTypes.String, XamlIlTypes.Object) { IsStatic = false, DeclaringOnly = true, IsExactMatch = true }); INameScopeComplete = INameScope.GetMethod( new FindMethodMethodSignature("Complete", XamlIlTypes.Void) { IsStatic = false, DeclaringOnly = true, IsExactMatch = true }); NameScope = ctx.Configuration.TypeSystem.GetType("Avalonia.Controls.NameScope"); NameScopeSetNameScope = NameScope.GetMethod(new FindMethodMethodSignature("SetNameScope", XamlIlTypes.Void, StyledElement, INameScope) { IsStatic = true }); AvaloniaObjectSetValueMethod = AvaloniaObject.FindMethod("SetValue", XamlIlTypes.Void, false, AvaloniaProperty, XamlIlTypes.Object, BindingPriority); }
/// <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> /// Attaches the behavior to the specified <see cref="AvaloniaObject"/>. /// </summary> /// <param name="associatedObject">The <see cref="AvaloniaObject"/> to which to attach.</param> /// <exception cref="ArgumentNullException"><paramref name="associatedObject"/> is null.</exception> public void Attach(AvaloniaObject associatedObject) { if (associatedObject == AssociatedObject) { return; } if (AssociatedObject != null) { throw new InvalidOperationException(string.Format( CultureInfo.CurrentCulture, "An instance of a behavior cannot be attached to more than one object at a time.", associatedObject, AssociatedObject)); } Debug.Assert(associatedObject != null, "Cannot attach the behavior to a null object."); AssociatedObject = associatedObject ?? throw new ArgumentNullException(nameof(associatedObject)); OnAttached(); }
public PropertyDetails(AvaloniaObject o, AvaloniaProperty property) { _target = o; _property = property; Name = property.IsAttached ? $"[{property.OwnerType.Name}.{property.Name}]" : property.Name; UpdateGroup(); // TODO: Unsubscribe when view model is deactivated. o.GetObservable(property).Subscribe(x => { var diagnostic = o.GetDiagnostic(property); RaiseAndSetIfChanged(ref _value, diagnostic.Value); Priority = (diagnostic.Priority != BindingPriority.Unset) ? diagnostic.Priority.ToString() : diagnostic.Property.Inherits ? "Inherited" : "Unset"; Diagnostic = diagnostic.Diagnostic; }); }
/// <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 HtmlControl; if (control != null) { var htmlContainer = control._htmlContainer; if (e.Property == AvoidImagesLateLoadingProperty) { htmlContainer.AvoidImagesLateLoading = (bool)e.NewValue; } else if (e.Property == IsSelectionEnabledProperty) { htmlContainer.IsSelectionEnabled = (bool)e.NewValue; } else if (e.Property == IsContextMenuEnabledProperty) { htmlContainer.IsContextMenuEnabled = (bool)e.NewValue; } else if (e.Property == BaseStylesheetProperty) { var baseCssData = CssData.Parse(AvaloniaAdapter.Instance, (string)e.NewValue); control._baseCssData = baseCssData; htmlContainer.SetHtml(control.Text, baseCssData); } else if (e.Property == TextProperty) { htmlContainer.ScrollOffset = new Point(0, 0); htmlContainer.SetHtml((string)e.NewValue, control._baseCssData); control.InvalidateMeasure(); control.InvalidateVisual(); if (control.VisualRoot != null) { control.InvokeMouseMove(); } } } }
internal static IEnumerable <T> GetChildren <T>(this AvaloniaObject parent) where T : AvaloniaObject { var visual = parent as global::Avalonia.Visual; if (visual != null) { foreach (var child in (visual as global::Avalonia.VisualTree.IVisual).VisualChildren) { if (child is T) { yield return(child as T); } else { foreach (var subChild in (child as AvaloniaObject).GetChildren <T>()) { yield return(subChild); } } } } }
private void TryCreateRegion() { AvaloniaObject targetElement = this.TargetElement; if (targetElement == null) { this.Detach(); return; } if (targetElement.CheckAccess()) { this.Detach(); if (!this.regionCreated) { string regionName = this.RegionManagerAccessor.GetRegionName(targetElement); CreateRegion(targetElement, regionName); this.regionCreated = true; } } }
static void AutoWireViewModelChanged(AvaloniaObject control, AvaloniaPropertyChangedEventArgs e) { if (Design.IsDesignMode) { return; } if (!(bool)e.NewValue) { return; } var view = control as Control; if (view == null) { return; } var viewType = control.GetType(); var viewName = viewType.FullName.Replace(".Views.", ".ViewModels."); var viewAssemblyName = viewType.GetTypeInfo().Assembly.FullName; var windowType = typeof(StyledWindow); if (windowType.IsAssignableFrom(viewType)) { ThemeManager.Instance.EnableTheme(view as StyledWindow); } var viewModelName = string.Format(CultureInfo.InvariantCulture, "{0}Model, {1}", viewName, viewAssemblyName); var viewModelType = Type.GetType(viewModelName); var viewModel = ServiceLocator.Instance.Container.GetService(viewModelType) as ViewModelBase; view.DataContext = viewModel; viewModel.IsLoaded = true; }
/// <summary> /// This method adds the default behaviors by using the <see cref="IRegionBehaviorFactory"/> object. /// </summary> /// <param name="region">The region being used.</param> /// <param name="regionTarget">The object to adapt.</param> protected virtual void AttachDefaultBehaviors(IRegion region, T regionTarget) { if (region == null) { throw new ArgumentNullException(nameof(region)); } if (regionTarget == null) { throw new ArgumentNullException(nameof(regionTarget)); } IRegionBehaviorFactory behaviorFactory = this.RegionBehaviorFactory; if (behaviorFactory != null) { AvaloniaObject AvaloniaObjectRegionTarget = regionTarget as AvaloniaObject; foreach (string behaviorKey in behaviorFactory) { if (!region.Behaviors.ContainsKey(behaviorKey)) { IRegionBehavior behavior = behaviorFactory.CreateFromKey(behaviorKey); if (AvaloniaObjectRegionTarget != null) { IHostAwareRegionBehavior hostAwareRegionBehavior = behavior as IHostAwareRegionBehavior; if (hostAwareRegionBehavior != null) { hostAwareRegionBehavior.HostControl = AvaloniaObjectRegionTarget; } } region.Behaviors.Add(behaviorKey, behavior); } } } }
/// <summary> /// Gets a diagnostic for a <see cref="AvaloniaProperty"/> on a <see cref="AvaloniaObject"/>. /// </summary> /// <param name="o">The object.</param> /// <param name="property">The property.</param> /// <returns> /// A <see cref="AvaloniaPropertyValue"/> that can be used to diagnose the state of the /// property on the object. /// </returns> public static AvaloniaPropertyValue GetDiagnostic(this AvaloniaObject o, AvaloniaProperty property) { var set = o.GetSetValues(); PriorityValue value; if (set.TryGetValue(property, out value)) { return(new AvaloniaPropertyValue( property, o.GetValue(property), (BindingPriority)value.ValuePriority, value.GetDiagnostic())); } else { return(new AvaloniaPropertyValue( property, o.GetValue(property), BindingPriority.Unset, "Unset")); } }
public IDisposable BindConstraints(AvaloniaObject popup, StyledProperty <double> widthProperty, StyledProperty <double> minWidthProperty, StyledProperty <double> maxWidthProperty, StyledProperty <double> heightProperty, StyledProperty <double> minHeightProperty, StyledProperty <double> maxHeightProperty, StyledProperty <bool> topmostProperty) { var bindings = new List <IDisposable>(); void Bind(AvaloniaProperty what, AvaloniaProperty to) => bindings.Add(this.Bind(what, popup[~to])); Bind(WidthProperty, widthProperty); Bind(MinWidthProperty, minWidthProperty); Bind(MaxWidthProperty, maxWidthProperty); Bind(HeightProperty, heightProperty); Bind(MinHeightProperty, minHeightProperty); Bind(MaxHeightProperty, maxHeightProperty); Bind(TopmostProperty, topmostProperty); return(Disposable.Create(() => { foreach (var x in bindings) { x.Dispose(); } })); }
private void GetRequestedBounds( ILayoutable el, out Rect bounds, out Rect marginBounds ) { // TODO: implement GetRight and GetBottom double left = 0, top = 0; Thickness margin = new Thickness(); AvaloniaObject content = el as AvaloniaObject; if (el is IContentPresenter presenter) { content = presenter.GetVisualChildren().OfType <AvaloniaObject>().FirstOrDefault(); } if (content != null) { left = GetLeft(content); top = GetTop(content); if (content is ILayoutable layoutable) { margin = layoutable.Margin; } } if (double.IsNaN(left)) { left = 0; } if (double.IsNaN(top)) { top = 0; } Size size = el.DesiredSize; bounds = new Rect(left + margin.Left, top + margin.Top, size.Width, size.Height); marginBounds = new Rect(left, top, size.Width + margin.Left + margin.Right, size.Height + margin.Top + margin.Bottom); }
//private Storyboard CurrentTransition //{ // get { return this.currentTransition; } // set // { // // decouple event // if (this.currentTransition != null) // { // this.currentTransition.Completed -= this.OnTransitionCompleted; // } // this.currentTransition = value; // if (this.currentTransition != null) // { // this.currentTransition.Completed += this.OnTransitionCompleted; // } // } //} private static void OnTransitionPropertyChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e) { var source = (FormsTransitioningContentControl)d; var oldTransition = (TransitionType)e.OldValue; var newTransition = (TransitionType)e.NewValue; if (source.IsTransitioning) { source.AbortTransition(); } // find new transition //Storyboard newStoryboard = source.GetStoryboard(newTransition); // unable to find the transition. //if (newStoryboard == null) //{ // // could be during initialization of xaml that presentationgroups was not yet defined // if (VisualStates.TryGetVisualStateGroup(source, PresentationGroup) == null) // { // // will delay check // source.CurrentTransition = null; // } // else // { // // revert to old value // source.SetValue(TransitionProperty, oldTransition); // throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Temporary removed exception message", newTransition)); // } //} //else //{ // source.CurrentTransition = newStoryboard; //} }
public static ItemsControl GetItemsOwner(AvaloniaObject element) { ItemsControl container = null; Panel panel = element as Panel; if (panel != null /*&& panel.Isi*/) { // see if element was generated for an ItemsPresenter ItemsPresenter ip = FromPanel(panel); if (ip != null) { // if so use the element whose style begat the ItemsPresenter container = ip.Parent as ItemsControl; } else { // otherwise use element's templated parent container = panel.TemplatedParent as ItemsControl; } } return(container); }
private static void SuspendHandler(this AvaloniaObject obj, AvaloniaProperty AvaloniaProperty, bool suspend) { if (_suspendedHandlers.ContainsKey(obj)) { Dictionary <AvaloniaProperty, bool> suspensions = _suspendedHandlers[obj]; if (suspend) { Debug.Assert(!suspensions.ContainsKey(AvaloniaProperty)); suspensions[AvaloniaProperty] = true; // true = dummy value } else { Debug.Assert(suspensions.ContainsKey(AvaloniaProperty)); suspensions.Remove(AvaloniaProperty); } } else { Debug.Assert(suspend); _suspendedHandlers[obj] = new Dictionary <AvaloniaProperty, bool>(); _suspendedHandlers[obj][AvaloniaProperty] = true; } }
/// <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> /// Gets all <see cref="AvaloniaProperty"/>s registered on a object. /// </summary> /// <param name="o">The object.</param> /// <returns>A collection of <see cref="AvaloniaProperty"/> definitions.</returns> public IEnumerable<AvaloniaProperty> GetRegistered(AvaloniaObject o) { Contract.Requires<ArgumentNullException>(o != null); return GetRegistered(o.GetType()); }
/// <summary> /// Gets renderer attached property. /// </summary> /// <param name="obj">The avalonia object.</param> /// <returns>The shape renderer property.</returns> public static IShapeRenderer GetRenderer(AvaloniaObject obj) { return(obj.GetValue(RendererProperty)); }
/// <summary> /// Gets data flow attached property. /// </summary> /// <param name="obj">The avalonia object.</param> /// <returns>The data flow property.</returns> public static IDataFlow GetDataFlow(AvaloniaObject obj) { return(obj.GetValue(DataFlowProperty)); }
public static string GetName(AvaloniaObject avaloniaObject) => avaloniaObject.GetValue(NameProperty);
public static void SetHotKey(AvaloniaObject target, KeyGesture value) => target.SetValue(HotKeyProperty, 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); }
public AvaloniaXamlIlWellKnownTypes(TransformerConfiguration cfg) { XamlIlTypes = cfg.WellKnownTypes; AvaloniaObject = cfg.TypeSystem.GetType("Avalonia.AvaloniaObject"); IAvaloniaObject = cfg.TypeSystem.GetType("Avalonia.IAvaloniaObject"); AvaloniaObjectExtensions = cfg.TypeSystem.GetType("Avalonia.AvaloniaObjectExtensions"); AvaloniaProperty = cfg.TypeSystem.GetType("Avalonia.AvaloniaProperty"); AvaloniaPropertyT = cfg.TypeSystem.GetType("Avalonia.AvaloniaProperty`1"); BindingPriority = cfg.TypeSystem.GetType("Avalonia.Data.BindingPriority"); IBinding = cfg.TypeSystem.GetType("Avalonia.Data.IBinding"); IDisposable = cfg.TypeSystem.GetType("System.IDisposable"); Transitions = cfg.TypeSystem.GetType("Avalonia.Animation.Transitions"); AssignBindingAttribute = cfg.TypeSystem.GetType("Avalonia.Data.AssignBindingAttribute"); AvaloniaObjectBindMethod = AvaloniaObjectExtensions.FindMethod("Bind", IDisposable, false, IAvaloniaObject, AvaloniaProperty, IBinding, cfg.WellKnownTypes.Object); UnsetValueType = cfg.TypeSystem.GetType("Avalonia.UnsetValueType"); StyledElement = cfg.TypeSystem.GetType("Avalonia.StyledElement"); INameScope = cfg.TypeSystem.GetType("Avalonia.Controls.INameScope"); INameScopeRegister = INameScope.GetMethod( new FindMethodMethodSignature("Register", XamlIlTypes.Void, XamlIlTypes.String, XamlIlTypes.Object) { IsStatic = false, DeclaringOnly = true, IsExactMatch = true }); INameScopeComplete = INameScope.GetMethod( new FindMethodMethodSignature("Complete", XamlIlTypes.Void) { IsStatic = false, DeclaringOnly = true, IsExactMatch = true }); NameScope = cfg.TypeSystem.GetType("Avalonia.Controls.NameScope"); NameScopeSetNameScope = NameScope.GetMethod(new FindMethodMethodSignature("SetNameScope", XamlIlTypes.Void, StyledElement, INameScope) { IsStatic = true }); AvaloniaObjectSetValueMethod = AvaloniaObject.FindMethod("SetValue", XamlIlTypes.Void, false, AvaloniaProperty, XamlIlTypes.Object, BindingPriority); IPropertyInfo = cfg.TypeSystem.GetType("Avalonia.Data.Core.IPropertyInfo"); ClrPropertyInfo = cfg.TypeSystem.GetType("Avalonia.Data.Core.ClrPropertyInfo"); PropertyPath = cfg.TypeSystem.GetType("Avalonia.Data.Core.PropertyPath"); PropertyPathBuilder = cfg.TypeSystem.GetType("Avalonia.Data.Core.PropertyPathBuilder"); IPropertyAccessor = cfg.TypeSystem.GetType("Avalonia.Data.Core.Plugins.IPropertyAccessor"); PropertyInfoAccessorFactory = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.PropertyInfoAccessorFactory"); CompiledBindingPathBuilder = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.CompiledBindingPathBuilder"); CompiledBindingPath = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.CompiledBindingPath"); CompiledBindingExtension = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindingExtension"); ResolveByNameExtension = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.ResolveByNameExtension"); DataTemplate = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.Templates.DataTemplate"); IDataTemplate = cfg.TypeSystem.GetType("Avalonia.Controls.Templates.IDataTemplate"); IItemsPresenterHost = cfg.TypeSystem.GetType("Avalonia.Controls.Presenters.IItemsPresenterHost"); ItemsRepeater = cfg.TypeSystem.GetType("Avalonia.Controls.ItemsRepeater"); ReflectionBindingExtension = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.ReflectionBindingExtension"); RelativeSource = cfg.TypeSystem.GetType("Avalonia.Data.RelativeSource"); UInt = cfg.TypeSystem.GetType("System.UInt32"); Long = cfg.TypeSystem.GetType("System.Int64"); Uri = cfg.TypeSystem.GetType("System.Uri"); FontFamily = cfg.TypeSystem.GetType("Avalonia.Media.FontFamily"); FontFamilyConstructorUriName = FontFamily.GetConstructor(new List <IXamlType> { Uri, XamlIlTypes.String }); (IXamlType, IXamlConstructor) GetNumericTypeInfo(string name, IXamlType componentType, int componentCount) { var type = cfg.TypeSystem.GetType(name); var ctor = type.GetConstructor(Enumerable.Range(0, componentCount).Select(_ => componentType).ToList()); return(type, ctor); } (Thickness, ThicknessFullConstructor) = GetNumericTypeInfo("Avalonia.Thickness", XamlIlTypes.Double, 4); (Point, PointFullConstructor) = GetNumericTypeInfo("Avalonia.Point", XamlIlTypes.Double, 2); (Vector, VectorFullConstructor) = GetNumericTypeInfo("Avalonia.Vector", XamlIlTypes.Double, 2); (Size, SizeFullConstructor) = GetNumericTypeInfo("Avalonia.Size", XamlIlTypes.Double, 2); (Matrix, MatrixFullConstructor) = GetNumericTypeInfo("Avalonia.Matrix", XamlIlTypes.Double, 6); (CornerRadius, CornerRadiusFullConstructor) = GetNumericTypeInfo("Avalonia.CornerRadius", XamlIlTypes.Double, 4); GridLength = cfg.TypeSystem.GetType("Avalonia.Controls.GridLength"); GridLengthConstructorValueType = GridLength.GetConstructor(new List <IXamlType> { XamlIlTypes.Double, cfg.TypeSystem.GetType("Avalonia.Controls.GridUnitType") }); Color = cfg.TypeSystem.GetType("Avalonia.Media.Color"); StandardCursorType = cfg.TypeSystem.GetType("Avalonia.Input.StandardCursorType"); Cursor = cfg.TypeSystem.GetType("Avalonia.Input.Cursor"); CursorTypeConstructor = Cursor.GetConstructor(new List <IXamlType> { StandardCursorType }); }
/// <summary> /// Finds a registered property on an object by name. /// </summary> /// <param name="o">The object.</param> /// <param name="name"> /// The property name. If an attached property it should be in the form /// "OwnerType.PropertyName". /// </param> /// <returns> /// The registered property or null if no matching property found. /// </returns> public AvaloniaProperty FindRegistered(AvaloniaObject o, string name) { return FindRegistered(o.GetType(), name); }
/// <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> /// Gets the value of the Right attached property for a control. /// </summary> /// <param name="element">The control.</param> /// <returns>The control's right coordinate.</returns> public static double GetRight(AvaloniaObject element) { return element.GetValue(RightProperty); }
public TargetBindingEndpoint(AvaloniaObject obj, AvaloniaProperty property) { Object = obj; Property = property; }
/// <summary> /// Gets the value of the Column attached property for a control. /// </summary> /// <param name="element">The control.</param> /// <returns>The control's column.</returns> public static int GetColumn(AvaloniaObject element) { return element.GetValue(ColumnProperty); }
/// <summary> /// Gets the value of the RowSpan attached property for a control. /// </summary> /// <param name="element">The control.</param> /// <returns>The control's row span.</returns> public static int GetRowSpan(AvaloniaObject element) { return element.GetValue(RowSpanProperty); }
private static int ValidateRow(AvaloniaObject o, int value) { if (value < 0) { throw new ArgumentException("Invalid Grid.Row value."); } return value; }
private static Vector ValidateOffset(AvaloniaObject o, Vector value) { ScrollViewer scrollViewer = o as ScrollViewer; if (scrollViewer != null) { var extent = scrollViewer.Extent; var viewport = scrollViewer.Viewport; return CoerceOffset(extent, viewport, value); } else { return value; } }
/// <summary> /// Gets renderer options attached property. /// </summary> /// <param name="obj">The avalonia object.</param> /// <returns>The shape renderer property.</returns> public static ShapeRenderer GetRenderer(AvaloniaObject obj) { return obj.GetValue(RendererProperty); }
/// <summary> /// Gets the value of the Bottom attached property for a control. /// </summary> /// <param name="element">The control.</param> /// <returns>The control's bottom coordinate.</returns> public static double GetBottom(AvaloniaObject element) { return element.GetValue(BottomProperty); }
/// <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); }
private static AvaloniaProperty?LookupProperty(AvaloniaObject o, string propertyName) { return(AvaloniaPropertyRegistry.Instance.FindRegistered(o, propertyName)); }
public static void SetHotKey(AvaloniaObject target, KeyGesture value) => target.SetValue(HotKeyProperty, value);
public static void SetName(AvaloniaObject avaloniaObject, string value) => avaloniaObject.SetValue(NameProperty, value);
public static KeyGesture GetHotKey(AvaloniaObject target) => target.GetValue(HotKeyProperty);
public static KeyGesture GetHotKey(AvaloniaObject target) => target.GetValue(HotKeyProperty);
/// <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); }
/// <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> /// Gets the value of the Top attached property for a control. /// </summary> /// <param name="element">The control.</param> /// <returns>The control's top coordinate.</returns> public static double GetTop(AvaloniaObject element) { return element.GetValue(TopProperty); }
/// <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); }
/// <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); }