Git Product home page Git Product logo

avaloniaautogrid's Introduction

Avalonia Auto

A flexible, easy to configure replacement for the standard Grid control. Ported from WPF AutoGrid

Now Available on NuGet! https://www.nuget.org/packages/Avalonia.AutoGrid/

AutoGrid lets you reduce the amount of xaml when using grids for layout by allowing you to define rows and columns as simple properties and alleviating you from having to explicitly specify the row and column a child control belongs to.

Partially based on work at http://rachel53461.wordpress.com/2011/09/17/wpf-grids-rowcolumn-count-properties/

Standard WPF Grid

<Grid>
  <Grid.RowDefinitions>
    <RowDefinition Height="35" />
    <RowDefinition Height="35" />
  </Grid.RowDefinitions>
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="100" />
    <ColumnDefinition Width="auto" />
  </Grid.ColumnDefinitions>
  
  <Label Grid.Row="0" Grid.Column="0" />
  <TextBox Grid.Row="0" Grid.Column="1" />
  <Label Grid.Row="1" Grid.Column="0" />
  <TextBox Grid.Row="1" Grid.Column="1" />
</Grid>

AutoGrid (Same output as above)

<AutoGrid RowCount="2" RowHeight="35" Columns="100,auto">
  <Label />
  <TextBox />
  <Label />
  <TextBox />
</AutoGrid>

Notice how in the example above we didn't need to specify the row and column that each element belonged to; AutoGrid automatically figures out what row and column we wanted based on our configuration of the grid. AutoGrid uses a row first or column first arrangement for its auto layout which can changed by setting the Orientation property.

Don't want AutoGrid to position elements automatically? OK

Explicit assignment of columns and rows still works too. This allows you to upgrade more easily. Most of time you can mix both without much trouble, but take care that this is not always the case.

Defining a even spaced 6x6 grid with a default margin of 10 for all cells

<local:AutoGrid ColumnCount="6" ColumnWidth="*" RowHeight="*" RowCount="6" ChildMargin="10" />

Grid with relative based column widths and fixed row height

<local:AutoGrid Columns="2*,5*" RowCount="6" RowHeight="25" />

Orientation="Horizontal" (default)

In this example, labels will fall in the first column, and textboxes will be in the second column

<AutoGrid RowCount="2" RowHeight="35" Columns="100,auto">
  <Label />     <!-- Col=0, Row=0 -->
  <TextBox />   <!-- Col=1, Row=0 -->
  <Label />     <!-- Col=0, Row=1 -->
  <TextBox />   <!-- Col=1, Row=1 -->
</AutoGrid>

Orientation="Vertical"

In this example, labels will fall in the first row, and textboxes will be in the second row

<AutoGrid RowCount="2" RowHeight="35" Columns="100,auto" Orientation="Vertical">
  <Label />     <!-- Col=0, Row=0 -->
  <TextBox />   <!-- Col=0, Row=1 -->
  <Label />     <!-- Col=1, Row=0 -->
  <TextBox />   <!-- Col=1, Row=1 -->
</AutoGrid>

Support for collapsed children

Collapsed elements will be removed from the flow, hidden elements will still occupy space in the grid

<AutoGrid RowCount="2" RowHeight="35" Columns="100,auto">
  <Label />                             <!-- Col=0, Row=0 -->
  <TextBox />                           <!-- Col=1, Row=0 -->
  <Label Visibility="Collapsed" />
  <TextBox />                           <!-- Col=0, Row=1 -->
</AutoGrid>

avaloniaautogrid's People

Contributors

kekekeks avatar vanillajonathan 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.