Git Product home page Git Product logo

avaloniagriddefinitionbehavoir's Introduction

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>

avaloniagriddefinitionbehavoir's People

Contributors

budul100 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.