RelativeControl.Avalonia 12.0.1

dotnet add package RelativeControl.Avalonia --version 12.0.1
                    
NuGet\Install-Package RelativeControl.Avalonia -Version 12.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RelativeControl.Avalonia" Version="12.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RelativeControl.Avalonia" Version="12.0.1" />
                    
Directory.Packages.props
<PackageReference Include="RelativeControl.Avalonia" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RelativeControl.Avalonia --version 12.0.1
                    
#r "nuget: RelativeControl.Avalonia, 12.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RelativeControl.Avalonia@12.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RelativeControl.Avalonia&version=12.0.1
                    
Install as a Cake Addin
#tool nuget:?package=RelativeControl.Avalonia&version=12.0.1
                    
Install as a Cake Tool

RelativeControl.Avalonia

This provides some relative units and features for Avalonia.

中文

See Usages in Demo

More Info

Get Started

Add NuGet package:

dotnet add package RelativeControl.Avalonia

Set a property whose value is double

<CONTROL r:Relative.Width="20pw"/>

This will set the CONTROL's width to 20% of its logical parent's width.

You can also add / subtract the values:

<CONTROL r:Relative.Width="20pw+10ph"/>

This will set the CONTROL's width to :

20% logical parent width + 10% logical parent height.

You can also add / subtract / multiply / divide the value at code behind.

  • Multiply() and Divide() will affect the instance and all its references.
  • * or / operation will create a light copy and will not affect the instance.

Relative.SetOneTimeWidth and Relative.SetOneTimeHeight will update only once when the control is attached to visual tree.

Other properties using RelativeLength / RelativeLengthMerge:

  • Relative.Height
  • Relative.MinWidth
  • Relative.MinHeight
  • Relative.MaxWidth
  • Relative.MaxHeight
  • Relative.SetOneTimeWidth
  • Relative.SetOneTimeHeight

Set a property whose value is CornerRadius

<CONTROL r:Relative.CornerRadius="10sw 10sw+5sh 10sh-5sw 10sh"/>

This will set the CONTROL's CornerRadius to:

TopLeft = 10% width,

TopRight = 10% width + 5% height,

BottomRight = 10% height - 5% width,

BottomLeft = 10% height

Set a property whose value is Thickness

<CONTROL r:Relative.BorderThickness="1em 2em-5px"/>

This will set the CONTROL's BorderThickness to:

Horizontal(Left,Right) = 1x FontSize,

Vertical(Top,Bottom) = 2x FontSize - 5px

Other properties using RelativeThickness:

  • Relative.Margin
  • Relative.Padding

Bind any property

<CONTROL PROPERTY="{Binding SOURCE_PROPERTY,Converter={x:Static r:RelativeConverter.Instance},ConverterParameter={r:Scale 50%}}"/>

This will set the PROPERTY's value to 50% of SOURCE_PROPERTY's value.

A valid SourceProperty's value must be:

  • a double
  • any value that can convert to double (like a number string)
  • any custom structs or classes that inherits IMulDiv<RelativeScale> or IMulDiv<double>.

RelativeBindOneTime will update only once when the control is attached to visual tree.

Use Relatives in your custom property:

StyledProperty:
public static readonly StyledProperty<IRelative<T>> XXXProperty = 
    AvaloniaProperty.Register<..., IRelative<T>>(nameof(XXX));
DirectProperty:
public static readonly DirectProperty<..., IRelative<T>> XXXProperty = 
    AvaloniaProperty.RegisterDirect<..., IRelative<T>>(...);
AttachedProperty:
public static readonly AttachedProperty<IRelative<T>> XXXProperty = 
    AvaloniaProperty.RegisterAttached<...,...,IRelative<T>>(...);

Units

Absolute Units:
px: Device-independent Pixel(1/96th of an inch)
cm: Centimeter
mm: Millimeter
in: Inch
Relative Units:
      tpw: TemplatedParent's width
      tph: TemplatedParent's height
lpw or pw: LogicalParent's width
lph or ph: LogicalParent's height
      vpw: VisualParent's width
      vph: VisualParent's height
       sw: The control itself's width
       sh: The control itself's height
       em: The control's FontSize
       vw: Window's width
       vh: Window's height
        %: Represents percentage. Only used for RelativeScale.
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on RelativeControl.Avalonia:

Package Downloads
RelativeControl.Avalonia.DataGrid

Enable Relative Units and Features for Avalonia DataGrid

GitHub repositories

This package is not used by any popular GitHub repositories.