Class Visual
- Namespace
- Avalonia
- Assembly
- Avalonia.Base.dll
Base class for controls that provides rendering and related visual properties.
[UsableDuringInitialization]
public class Visual : StyledElement, INotifyPropertyChanged, IDataContextProvider, ILogical, IThemeVariantHost, IResourceHost, IResourceNode, IStyleHost, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, IStyleable, INamed
- Inheritance
-
Visual
- Implements
- Derived
- Inherited Members
- Extension Methods
Remarks
The Visual class represents elements that have a visual on-screen representation and stores all the information needed for an IRenderer to render the control. To traverse the visual tree, use the extension methods defined in VisualExtensions.
Constructors
Visual()
Initializes a new instance of the Visual class.
public Visual()
Fields
BoundsProperty
Defines the Bounds property.
public static readonly DirectProperty<Visual, Rect> BoundsProperty
Field Value
ClipProperty
Defines the Clip property.
public static readonly StyledProperty<Geometry?> ClipProperty
Field Value
ClipToBoundsProperty
Defines the ClipToBounds property.
public static readonly StyledProperty<bool> ClipToBoundsProperty
Field Value
EffectProperty
Defines the Effect property.
public static readonly StyledProperty<IEffect?> EffectProperty
Field Value
FlowDirectionProperty
Defines the FlowDirection property.
public static readonly AttachedProperty<FlowDirection> FlowDirectionProperty
Field Value
HasMirrorTransformProperty
Defines the HasMirrorTransform property.
public static readonly DirectProperty<Visual, bool> HasMirrorTransformProperty
Field Value
IsVisibleProperty
Defines the IsVisible property.
public static readonly StyledProperty<bool> IsVisibleProperty
Field Value
OpacityMaskProperty
Defines the OpacityMask property.
public static readonly StyledProperty<IBrush?> OpacityMaskProperty
Field Value
OpacityProperty
Defines the Opacity property.
public static readonly StyledProperty<double> OpacityProperty
Field Value
RenderTransformOriginProperty
Defines the RenderTransformOrigin property.
public static readonly StyledProperty<RelativePoint> RenderTransformOriginProperty
Field Value
RenderTransformProperty
Defines the RenderTransform property.
public static readonly StyledProperty<ITransform?> RenderTransformProperty
Field Value
VisualParentProperty
Defines the Avalonia.Visual.VisualParent property.
public static readonly DirectProperty<Visual, Visual?> VisualParentProperty
Field Value
ZIndexProperty
Defines the ZIndex property.
public static readonly StyledProperty<int> ZIndexProperty
Field Value
Properties
Bounds
Gets the bounds of the control relative to its parent.
public Rect Bounds { get; protected set; }
Property Value
BypassFlowDirectionPolicies
Gets a value indicating whether control bypass FlowDirecton policies.
protected virtual bool BypassFlowDirectionPolicies { get; }
Property Value
Remarks
Related to FlowDirection system and returns false as default, so if FlowDirection is RTL then control will get a mirror presentation. For controls that want to avoid this behavior, override this property and return true.
Clip
Gets or sets the geometry clip for this visual.
public Geometry? Clip { get; set; }
Property Value
ClipToBounds
Gets or sets a value indicating whether the control should be clipped to its bounds.
public bool ClipToBounds { get; set; }
Property Value
Effect
Gets or sets the effect of the control.
public IEffect? Effect { get; set; }
Property Value
FlowDirection
Gets or sets the text flow direction.
public FlowDirection FlowDirection { get; set; }
Property Value
HasMirrorTransform
Gets or sets a value indicating whether to apply mirror transform on this control.
public bool HasMirrorTransform { get; protected set; }
Property Value
IsEffectivelyVisible
Gets a value indicating whether this control and all its parents are visible.
public bool IsEffectivelyVisible { get; }
Property Value
IsVisible
Gets or sets a value indicating whether this control is visible.
public bool IsVisible { get; set; }
Property Value
Opacity
Gets or sets the opacity of the control.
public double Opacity { get; set; }
Property Value
OpacityMask
Gets or sets the opacity mask of the control.
public IBrush? OpacityMask { get; set; }
Property Value
RenderTransform
Gets or sets the render transform of the control.
public ITransform? RenderTransform { get; set; }
Property Value
RenderTransformOrigin
Gets or sets the transform origin of the control.
public RelativePoint RenderTransformOrigin { get; set; }
Property Value
VisualChildren
Gets the control's child visuals.
protected IAvaloniaList<Visual> VisualChildren { get; }
Property Value
VisualRoot
Gets the root of the visual tree, if the control is attached to a visual tree.
protected IRenderRoot? VisualRoot { get; }
Property Value
ZIndex
Gets or sets the Z index of the control.
public int ZIndex { get; set; }
Property Value
Remarks
Controls with a higher ZIndex will appear in front of controls with a lower ZIndex. If two controls have the same ZIndex then the control that appears later in the containing element's children collection will appear on top.
Methods
AffectsRender<T>(params AvaloniaProperty[])
Indicates that a property change should cause InvalidateVisual() to be called.
protected static void AffectsRender<T>(params AvaloniaProperty[] properties) where T : Visual
Parameters
properties
AvaloniaProperty[]The properties.
Type Parameters
T
The control which the property affects.
Remarks
This method should be called in a control's static constructor with each property on the control which when changed should cause a redraw. This is similar to WPF's FrameworkPropertyMetadata.AffectsRender flag.
GetFlowDirection(Visual)
Gets the value of the attached FlowDirectionProperty on a control.
public static FlowDirection GetFlowDirection(Visual visual)
Parameters
visual
VisualThe control.
Returns
- FlowDirection
The flow direction.
InvalidateMirrorTransform()
Computes the HasMirrorTransform value according to the FlowDirection and BypassFlowDirectionPolicies
protected virtual void InvalidateMirrorTransform()
InvalidateVisual()
Invalidates the visual and queues a repaint.
public void InvalidateVisual()
LogicalChildrenCollectionChanged(object?, NotifyCollectionChangedEventArgs)
protected override void LogicalChildrenCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
Parameters
sender
objecte
NotifyCollectionChangedEventArgs
OnAttachedToVisualTree(VisualTreeAttachmentEventArgs)
Called when the control is added to a rooted visual tree.
protected virtual void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
Parameters
e
VisualTreeAttachmentEventArgsThe event args.
OnAttachedToVisualTreeCore(VisualTreeAttachmentEventArgs)
Calls the OnAttachedToVisualTree(VisualTreeAttachmentEventArgs) method for this control and all of its visual descendants.
protected virtual void OnAttachedToVisualTreeCore(VisualTreeAttachmentEventArgs e)
Parameters
e
VisualTreeAttachmentEventArgsThe event args.
OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs)
Called when the control is removed from a rooted visual tree.
protected virtual void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
Parameters
e
VisualTreeAttachmentEventArgsThe event args.
OnDetachedFromVisualTreeCore(VisualTreeAttachmentEventArgs)
Calls the OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs) method for this control and all of its visual descendants.
protected virtual void OnDetachedFromVisualTreeCore(VisualTreeAttachmentEventArgs e)
Parameters
e
VisualTreeAttachmentEventArgsThe event args.
OnPropertyChanged(AvaloniaPropertyChangedEventArgs)
Called when a avalonia property changes on the object.
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
Parameters
change
AvaloniaPropertyChangedEventArgsThe property change details.
OnVisualParentChanged(Visual?, Visual?)
Called when the control's visual parent changes.
protected virtual void OnVisualParentChanged(Visual? oldParent, Visual? newParent)
Parameters
Render(DrawingContext)
Renders the visual to a DrawingContext.
public virtual void Render(DrawingContext context)
Parameters
context
DrawingContextThe drawing context.
SetFlowDirection(Visual, FlowDirection)
Sets the value of the attached FlowDirectionProperty on a control.
public static void SetFlowDirection(Visual visual, FlowDirection value)
Parameters
visual
VisualThe control.
value
FlowDirectionThe property value to set.
Events
AttachedToVisualTree
Raised when the control is attached to a rooted visual tree.
public event EventHandler<VisualTreeAttachmentEventArgs>? AttachedToVisualTree
Event Type
DetachedFromVisualTree
Raised when the control is detached from a rooted visual tree.
public event EventHandler<VisualTreeAttachmentEventArgs>? DetachedFromVisualTree