Responsive.Avalonia
0.2.0
dotnet add package Responsive.Avalonia --version 0.2.0
NuGet\Install-Package Responsive.Avalonia -Version 0.2.0
<PackageReference Include="Responsive.Avalonia" Version="0.2.0" />
<PackageVersion Include="Responsive.Avalonia" Version="0.2.0" />
<PackageReference Include="Responsive.Avalonia" />
paket add Responsive.Avalonia --version 0.2.0
#r "nuget: Responsive.Avalonia, 0.2.0"
#:package Responsive.Avalonia@0.2.0
#addin nuget:?package=Responsive.Avalonia&version=0.2.0
#tool nuget:?package=Responsive.Avalonia&version=0.2.0
Responsive.Avalonia - Use Breakpoints in AvaloniaUI
Overview
Responsive.Avalonia is a library that provides responsive breakpoints for AvaloniaUI applications. It allows developers to create responsive layouts that adapt to different screen sizes using predefined breakpoints.
Features
Custom conditions can now be added by using the Condition property of the Show control. Read more in this section: Custom Conditions.
- Predefined Breakpoints: Use predefined breakpoints such as
Xs,Sm,Md,Lg,Xl, andXxl. - Customizable Visibility: Control the visibility of UI elements based on the current screen width or height.
- Orientation Mode: Toggle between horizontal (width-based) and vertical (height-based) breakpoints using the
Orientationproperty onBreakpointProvider. - Easy Integration: Simple to integrate into existing AvaloniaUI projects.
Installation
You can install the library via NuGet Package Manager:
dotnet add package Responsive.Avalonia
Usage
Add Namespace
xmlns:rc="using:Responsive.Avalonia"
There are two controls needed to be used. The BreakpointProvider is the root that detects
the size changes, and the Show control contains the elements that will be shown when the measured length
(width or height, depending on orientation) is within the breakpoint.
Orientation Mode
By default, breakpoints are based on width (horizontal mode). To use height (vertical mode), set the Orientation property on BreakpointProvider:
<rc:BreakpointProvider Orientation="Vertical">
</rc:BreakpointProvider>
Or in code:
breakpointProvider.Orientation = ResponsiveOrientationMode.Vertical;
Example
<rc:BreakpointProvider Orientation="Horizontal">
<rc:Show Breakpoint="Xs">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White"
FontWeight="Medium" FontSize="14" Text="Visible on Small Screens"/>
</rc:Show>
<rc:Show Breakpoint="Sm">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White"
FontWeight="Medium" FontSize="24" Text="Visible on Medium Screens"/>
</rc:Show>
<rc:Show Breakpoint="MdAndUp">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White"
FontWeight="Medium" FontSize="38" Text="Visible on Large Screens"/>
</rc:Show>
</rc:BreakpointProvider>
Show Control Properties
Breakpoint - Specifies the breakpoint at which the content should be visible. It is of type Breakpoint.
| Breakpoint | Pixel Equivalent |
|---|---|
| Breakpoint.Xs | length < 600px |
| Breakpoint.SmAndDown | length < 960px |
| Breakpoint.Sm | 600px ⇐ length < 960px |
| Breakpoint.SmAndUp | length >= 600px |
| Breakpoint.MdAndDown | length < 1280px |
| Breakpoint.Md | 960px ⇐ length < 1280px |
| Breakpoint.MdAndUp | length >= 960px |
| Breakpoint.LgAndDown | length < 1920px |
| Breakpoint.Lg | 1280px ⇐ length < 1920px |
| Breakpoint.LgAndUp | length >= 1280px |
| Breakpoint.XlAndDown | length < 2560px |
| Breakpoint.Xl | 1920px ⇐ length < 2560px |
| Breakpoint.XlAndUp | length >= 1920px |
| Breakpoint.Xxl | length >= 2560px |
Note: The
lengthrefers to width in horizontal mode and height in vertical mode, depending on theOrientationproperty of the nearestBreakpointProvider.
Condition - A custom condition that can be used to determine the visibility of the content. It is a Func<double,bool> delegate
that returns true if the content should be visible. See the Custom Conditions section for more details.
Invert - A boolean property that inverts the visibility condition. If set to true, the content will be hidden at the
specified breakpoint. This property is also respected when using the Condition property.
Custom Conditions
For more granular control, custom conditions can be used instead of the standard breakpoints. The condition receives the measured length (width or height, depending on orientation) of the breakpoint provider. For example, to show the element if the length is between 600 and 700 pixels:
using System;
namespace SampleApp;
public static class CustomBreakpoints
{
// Example implementation of a custom breakpoint for demonstration purposes.
public static Func<double,bool> Length600To700Condition => length => length is >= 600 and < 700;
}
To use this, set the Condition property of the Show control:
<rc:Show Condition="{x:Static sampleApp:CustomBreakpoints.Length600To700Condition}">
<TextBlock Text="Visible if length is between 600px and 700px" />
</rc:Show>
When using custom conditions, the Breakpoint property will be ignored.
The value passed to the condition is the measured width or height, depending on the orientation.
License
This project is licensed under the MIT License. See the LICENSE file for more details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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 was computed. 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 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Avalonia (>= 11.1.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
0.2.0 - Added support for responsive orientation mode (Vertical or Horizontal).
0.1.1 - Added custom conditions for granular breakpoint control.