budul.AvaloniaGridDefinitionBehavoir 1.1.1

dotnet add package budul.AvaloniaGridDefinitionBehavoir --version 1.1.1                
NuGet\Install-Package budul.AvaloniaGridDefinitionBehavoir -Version 1.1.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="budul.AvaloniaGridDefinitionBehavoir" Version="1.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add budul.AvaloniaGridDefinitionBehavoir --version 1.1.1                
#r "nuget: budul.AvaloniaGridDefinitionBehavoir, 1.1.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.
// Install budul.AvaloniaGridDefinitionBehavoir as a Cake Addin
#addin nuget:?package=budul.AvaloniaGridDefinitionBehavoir&version=1.1.1

// Install budul.AvaloniaGridDefinitionBehavoir as a Cake Tool
#tool nuget:?package=budul.AvaloniaGridDefinitionBehavoir&version=1.1.1                

AvaloniaGridDefinitionBehavoir

This behavior allows the adjustment of the RowDefinitions / ColumnDefinitions of Avalonia Grids. It was inspired by a blog entry by Rachel Lim. This approach was initially shown for WPF Grids.

The behavior is available as NuGet package.

Nuget

Useage

The following code ...

<Grid>
	<Grid.RowDefinitions>
		<RowDefinition Height="Auto" />
		<RowDefinition Height="Auto" />
		<RowDefinition Height="Auto" />
		<RowDefinition Height="Auto" />
	</Grid.RowDefinitions>
	<Grid.ColumnDefinitions>
		<ColumnDefinition Width="Auto" />
		<ColumnDefinition Width="Auto" />
	</Grid.ColumnDefinitions>
</Grid>

... can be defined as follows:

<Grid
	avaloniaGridDefinitionBehavoir:GridDefinitionBehavior.RowCount="4"
	avaloniaGridDefinitionBehavoir:GridDefinitionBehavior.ColumnCount="2">
</Grid>

Definitions with stars must be set additionally by using regular expressions. The following output ...

<Grid>
	<Grid.RowDefinitions>
		<RowDefinition Height="Auto" />
		<RowDefinition Height="*" />
		<RowDefinition Height="Auto" />
		<RowDefinition Height="*" />
	</Grid.RowDefinitions>
	<Grid.ColumnDefinitions>
		<ColumnDefinition Width="*" />
		<ColumnDefinition Width="*" />
	</Grid.ColumnDefinitions>
</Grid>

... can be defined as follows:

<Grid
	avaloniaGridDefinitionBehavoir:GridDefinitionBehavior.RowCount="4"
	avaloniaGridDefinitionBehavoir:GridDefinitionBehavior.ColumnCount="2"
	avaloniaGridDefinitionBehavoir:GridDefinitionBehavior.StarRows="\d*[13579]"
	avaloniaGridDefinitionBehavoir:GridDefinitionBehavior.StarColumns=".*">
</Grid>

For MVVM apps the grid definitions can also be bound onto the view models. The following can be seen in the sample data.

<ItemsControl
	x:DataType="vm:MainWindowViewModel"
	DockPanel.Dock="Top"
	ItemsSource="{Binding Elements}">

	<ItemsControl.ItemsPanel>
		<ItemsPanelTemplate>
			<Grid
				HorizontalAlignment="Stretch"
				VerticalAlignment="Stretch"
				gridbehavior:GridDefinitionBehavior.ColumnCount="{Binding Columns}"
				gridbehavior:GridDefinitionBehavior.RowCount="{Binding Rows}"
				ShowGridLines="True" />
		</ItemsPanelTemplate>
	</ItemsControl.ItemsPanel>

	<ItemsControl.Styles>
		<Style x:DataType="md:Element" Selector="ItemsControl > ContentPresenter">
			<Setter Property="Grid.Row" Value="{Binding Row}" />
			<Setter Property="Grid.Column" Value="{Binding Column}" />
		</Style>
	</ItemsControl.Styles>

	<ItemsControl.ItemTemplate>
		<DataTemplate x:DataType="md:Element">
			<TextBlock Margin="10" Text="{Binding Name}" />
		</DataTemplate>
	</ItemsControl.ItemTemplate>
</ItemsControl>
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.1 185 2/6/2024
1.1.0 122 2/6/2024
1.0.0 218 11/27/2023