Initial commit
This commit is contained in:
Коммит
4f4506737e
|
@ -0,0 +1,108 @@
|
|||
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
.idea
|
||||
# mstest test results
|
||||
TestResults
|
||||
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.sln.docstates
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Rr]elease/
|
||||
x64/
|
||||
*_i.c
|
||||
*_p.c
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*
|
||||
|
||||
# NCrunch
|
||||
*.ncrunch*
|
||||
.*crunch*.local.xml
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish
|
||||
|
||||
# Publish Web Output
|
||||
*.Publish.xml
|
||||
|
||||
# NuGet Packages Directory
|
||||
packages
|
||||
|
||||
# Windows Azure Build Output
|
||||
csx
|
||||
*.build.csdef
|
||||
|
||||
# Windows Store app package directory
|
||||
AppPackages/
|
||||
|
||||
# Others
|
||||
[Bb]in
|
||||
[Oo]bj
|
||||
sql
|
||||
TestResults
|
||||
[Tt]est[Rr]esult*
|
||||
*.Cache
|
||||
ClientBin
|
||||
[Ss]tyle[Cc]op.*
|
||||
~$*
|
||||
*.dbmdl
|
||||
Generated_Code #added for RIA/Silverlight projects
|
||||
|
||||
# Backup & report files from converting an old project file to a newer
|
||||
# Visual Studio version. Backup files are not needed, because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageRestore>
|
||||
<add key="enabled" value="True" />
|
||||
<add key="automatic" value="True" />
|
||||
</packageRestore>
|
||||
<packageSources>
|
||||
<add key="NuGet 3 (plain)" value="http://api.nuget.org/v3/index.json" />
|
||||
<add key="Avalonia Nightly" value="https://www.myget.org/F/avalonia-ci/api/v2" />
|
||||
</packageSources>
|
||||
<bindingRedirects>
|
||||
<add key="skip" value="False" />
|
||||
</bindingRedirects>
|
||||
</configuration>
|
|
@ -0,0 +1,98 @@
|
|||
Avalonia Auto
|
||||
============
|
||||
|
||||
A flexible, easy to configure replacement for the standard Grid control. Ported from [WPF AutoGrid](https://github.com/carbonrobot/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>
|
||||
```
|
|
@ -0,0 +1,56 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26124.0
|
||||
MinimumVisualStudioVersion = 15.0.26124.0
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvaloniaAutoGrid", "src\AutoGrid\AvaloniaAutoGrid.csproj", "{45FC7547-7C8D-4562-8E9F-8DAA74795791}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{5715E0C9-3107-4803-A7DD-4D620D719884}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{911A44F9-4604-4C99-BF42-C1BF301FF5C6}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGridExamples", "samples\AutoGridExamples\AutoGridExamples.csproj", "{96686746-D11A-4B57-9DFD-BEC3350D247C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{45FC7547-7C8D-4562-8E9F-8DAA74795791}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{45FC7547-7C8D-4562-8E9F-8DAA74795791}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{45FC7547-7C8D-4562-8E9F-8DAA74795791}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{45FC7547-7C8D-4562-8E9F-8DAA74795791}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{45FC7547-7C8D-4562-8E9F-8DAA74795791}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{45FC7547-7C8D-4562-8E9F-8DAA74795791}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{45FC7547-7C8D-4562-8E9F-8DAA74795791}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{45FC7547-7C8D-4562-8E9F-8DAA74795791}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{45FC7547-7C8D-4562-8E9F-8DAA74795791}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{45FC7547-7C8D-4562-8E9F-8DAA74795791}.Release|x64.Build.0 = Release|Any CPU
|
||||
{45FC7547-7C8D-4562-8E9F-8DAA74795791}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{45FC7547-7C8D-4562-8E9F-8DAA74795791}.Release|x86.Build.0 = Release|Any CPU
|
||||
{96686746-D11A-4B57-9DFD-BEC3350D247C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{96686746-D11A-4B57-9DFD-BEC3350D247C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{96686746-D11A-4B57-9DFD-BEC3350D247C}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{96686746-D11A-4B57-9DFD-BEC3350D247C}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{96686746-D11A-4B57-9DFD-BEC3350D247C}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{96686746-D11A-4B57-9DFD-BEC3350D247C}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{96686746-D11A-4B57-9DFD-BEC3350D247C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{96686746-D11A-4B57-9DFD-BEC3350D247C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{96686746-D11A-4B57-9DFD-BEC3350D247C}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{96686746-D11A-4B57-9DFD-BEC3350D247C}.Release|x64.Build.0 = Release|Any CPU
|
||||
{96686746-D11A-4B57-9DFD-BEC3350D247C}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{96686746-D11A-4B57-9DFD-BEC3350D247C}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{45FC7547-7C8D-4562-8E9F-8DAA74795791} = {5715E0C9-3107-4803-A7DD-4D620D719884}
|
||||
{96686746-D11A-4B57-9DFD-BEC3350D247C} = {911A44F9-4604-4C99-BF42-C1BF301FF5C6}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,3 @@
|
|||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/CodeInspection/ExcludedFiles/FileMasksToSkip/=_002A_002Examl/@EntryIndexedValue">False</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/ExcludedFiles/FileMasksToSkip/=_002A_002Examl/@EntryIndexRemoved">True</s:Boolean></wpf:ResourceDictionary>
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Charles Brown (carbonrobot)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<Application xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<Application.Styles>
|
||||
<StyleInclude Source="resm:Avalonia.Themes.Default.DefaultTheme.xaml?assembly=Avalonia.Themes.Default"/>
|
||||
<StyleInclude Source="resm:Avalonia.Themes.Default.Accents.BaseLight.xaml?assembly=Avalonia.Themes.Default"/>
|
||||
</Application.Styles>
|
||||
</Application>
|
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using Avalonia;
|
||||
using Avalonia.Gtk3;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace AutoGridExamples
|
||||
{
|
||||
public class App : Application
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
BuildAvaloniaApp().Start<MainWindow>();
|
||||
}
|
||||
|
||||
static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure<App>()
|
||||
.UsePlatformDetect().UseGtk3(new Gtk3PlatformOptions { UseGpuAcceleration = true });
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\AutoGrid\AvaloniaAutoGrid.csproj" />
|
||||
<PackageReference Include="Avalonia.Desktop" Version="0.7.1-build1036-beta" />
|
||||
<EmbeddedResource Include="**\*.xaml"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,223 @@
|
|||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:AvaloniaAutoGrid;assembly=AvaloniaAutoGrid"
|
||||
xmlns:system="clr-namespace:System;assembly=System.Runtime"
|
||||
Title="MainWindow"
|
||||
Height="350"
|
||||
Width="525">
|
||||
|
||||
<ScrollViewer>
|
||||
|
||||
<UniformGrid>
|
||||
|
||||
<!-- Grid of 4 colors -->
|
||||
<local:AutoGrid ColumnCount="2"
|
||||
ColumnWidth="*"
|
||||
RowDefinitions="*,*"
|
||||
ChildMargin="2"
|
||||
Margin="5">
|
||||
|
||||
<Rectangle Fill="Blue" />
|
||||
<Rectangle Fill="Red" />
|
||||
<Rectangle Fill="Green" />
|
||||
<Rectangle Fill="Yellow" />
|
||||
|
||||
</local:AutoGrid>
|
||||
|
||||
<!-- Colspan Tests (default Orientation) -->
|
||||
<local:AutoGrid ColumnCount="3"
|
||||
ColumnWidth="*"
|
||||
RowCount="2"
|
||||
RowHeight="*"
|
||||
ChildMargin="2"
|
||||
Margin="5">
|
||||
|
||||
<Rectangle Fill="Blue"
|
||||
Grid.ColumnSpan="2" />
|
||||
<Rectangle Fill="Red" />
|
||||
<Rectangle Fill="Yellow" />
|
||||
<Rectangle Fill="Green"
|
||||
Grid.ColumnSpan="2" />
|
||||
|
||||
</local:AutoGrid>
|
||||
|
||||
<!-- Colspan + Rowspan Tests (default Orientation) -->
|
||||
<local:AutoGrid ColumnCount="3"
|
||||
ColumnWidth="*"
|
||||
RowCount="2"
|
||||
RowHeight="*"
|
||||
ChildMargin="2"
|
||||
Margin="5">
|
||||
|
||||
<Rectangle Fill="Blue"
|
||||
Grid.RowSpan="2" />
|
||||
<Rectangle Fill="Red" />
|
||||
<Rectangle Fill="Yellow" />
|
||||
<Rectangle Fill="Green"
|
||||
Grid.ColumnSpan="2" />
|
||||
|
||||
</local:AutoGrid>
|
||||
|
||||
<!-- Rowspan Tests, second child (default Orientation) -->
|
||||
<local:AutoGrid ColumnCount="3"
|
||||
ColumnWidth="*"
|
||||
RowCount="2"
|
||||
RowHeight="*"
|
||||
ChildMargin="2"
|
||||
Margin="5">
|
||||
|
||||
<Rectangle Fill="Blue" />
|
||||
<Rectangle Fill="Red"
|
||||
Grid.RowSpan="2" />
|
||||
<Rectangle Fill="Yellow" />
|
||||
<Rectangle Fill="Green" />
|
||||
<Rectangle Fill="Orange" />
|
||||
|
||||
</local:AutoGrid>
|
||||
|
||||
<!-- Rowspan Tests, third child (default Orientation) -->
|
||||
<local:AutoGrid ColumnCount="3"
|
||||
ColumnWidth="*"
|
||||
RowCount="2"
|
||||
RowHeight="*"
|
||||
ChildMargin="2"
|
||||
Margin="5">
|
||||
|
||||
<Rectangle Fill="Blue" />
|
||||
<Rectangle Fill="Red" />
|
||||
<Rectangle Fill="Yellow"
|
||||
Grid.RowSpan="2" />
|
||||
<Rectangle Fill="Green" />
|
||||
<Rectangle Fill="Orange" />
|
||||
|
||||
</local:AutoGrid>
|
||||
|
||||
<!-- Rowspan Tests, sufu (default Orientation) -->
|
||||
<local:AutoGrid ColumnCount="3"
|
||||
ColumnWidth="*"
|
||||
RowCount="2"
|
||||
RowHeight="*"
|
||||
ChildMargin="2"
|
||||
Margin="5">
|
||||
|
||||
<Rectangle Fill="Blue"
|
||||
Grid.RowSpan="2" />
|
||||
<Rectangle Fill="Red" />
|
||||
<Rectangle Fill="Yellow"
|
||||
Grid.RowSpan="2" />
|
||||
<Rectangle Fill="Green" />
|
||||
|
||||
</local:AutoGrid>
|
||||
|
||||
<!-- Rowspan Tests, first column (default Orientation) -->
|
||||
<local:AutoGrid ColumnCount="3"
|
||||
ColumnWidth="*"
|
||||
RowCount="2"
|
||||
RowHeight="*"
|
||||
ChildMargin="2"
|
||||
Margin="5">
|
||||
|
||||
<Rectangle Fill="Blue" Grid.RowSpan="2" />
|
||||
<Rectangle Fill="Red" />
|
||||
<Rectangle Fill="Yellow" />
|
||||
<Rectangle Fill="Green" />
|
||||
<Rectangle Fill="Orange" />
|
||||
|
||||
</local:AutoGrid>
|
||||
|
||||
|
||||
<!-- Colspan Tests, rowspan tests (Vertical Orientation) -->
|
||||
<local:AutoGrid ColumnCount="3"
|
||||
ColumnWidth="*"
|
||||
RowCount="2"
|
||||
RowHeight="*"
|
||||
ChildMargin="2"
|
||||
Orientation="Vertical"
|
||||
Margin="5">
|
||||
|
||||
<Rectangle Fill="Blue"
|
||||
Grid.RowSpan="2" />
|
||||
<Rectangle Fill="Red" />
|
||||
<Rectangle Fill="Yellow"
|
||||
Grid.RowSpan="2" />
|
||||
<Rectangle Fill="Green" />
|
||||
<Rectangle Fill="Orange" />
|
||||
|
||||
</local:AutoGrid>
|
||||
|
||||
<!-- Colspan Tests, colspan tests (Vertical Orientation) -->
|
||||
<local:AutoGrid ColumnCount="3"
|
||||
ColumnWidth="*"
|
||||
RowCount="2"
|
||||
RowHeight="*"
|
||||
ChildMargin="7"
|
||||
Orientation="Vertical"
|
||||
Margin="5">
|
||||
|
||||
<Rectangle Fill="Blue"
|
||||
Grid.ColumnSpan="2" />
|
||||
<Rectangle Fill="Red" />
|
||||
<Rectangle Fill="Yellow"
|
||||
Grid.RowSpan="2"
|
||||
Margin="7"/>
|
||||
<Rectangle Fill="Green" />
|
||||
<Rectangle Fill="Orange" />
|
||||
|
||||
</local:AutoGrid>
|
||||
|
||||
<!-- Binding Test -->
|
||||
<local:AutoGrid RowDefinitions="Auto,*"
|
||||
ColumnDefinitions="*"
|
||||
ChildMargin="5">
|
||||
<NumericUpDown Name="uxCombo" Value="2" Maximum="4" Minimum="1">
|
||||
|
||||
</NumericUpDown>
|
||||
<local:AutoGrid ColumnCount="{Binding ElementName=uxCombo, Path=Value}"
|
||||
ColumnWidth="*"
|
||||
RowHeight="*"
|
||||
RowCount="4"
|
||||
ChildMargin="1">
|
||||
|
||||
<Rectangle Fill="Blue" />
|
||||
<Rectangle Fill="Red" />
|
||||
<Rectangle Fill="Green" />
|
||||
<Rectangle Fill="Yellow" />
|
||||
|
||||
</local:AutoGrid>
|
||||
</local:AutoGrid>
|
||||
|
||||
<!-- Testing collapsed child row -->
|
||||
<local:AutoGrid ColumnCount="2"
|
||||
ColumnWidth="*"
|
||||
RowDefinitions="*,*,*"
|
||||
ChildMargin="2"
|
||||
Margin="5">
|
||||
|
||||
<Rectangle Fill="Blue" />
|
||||
<Rectangle Fill="Red" />
|
||||
<Rectangle Fill="Green" IsVisible="False" />
|
||||
<Rectangle Fill="Yellow" IsVisible="False" />
|
||||
<Rectangle Fill="Purple" />
|
||||
<Rectangle Fill="Pink" />
|
||||
|
||||
</local:AutoGrid>
|
||||
|
||||
<!-- Testing single collapsed child element -->
|
||||
<local:AutoGrid ColumnCount="2"
|
||||
ColumnWidth="*"
|
||||
RowDefinitions="*,*,*"
|
||||
ChildMargin="2"
|
||||
Margin="5">
|
||||
|
||||
<Rectangle Fill="Blue" />
|
||||
<Rectangle Fill="Red" />
|
||||
<Rectangle Fill="Green" />
|
||||
<Rectangle Fill="Yellow" IsVisible="False" />
|
||||
<Rectangle Fill="Purple" />
|
||||
<Rectangle Fill="Pink" />
|
||||
|
||||
</local:AutoGrid>
|
||||
|
||||
</UniformGrid>
|
||||
</ScrollViewer>
|
||||
</Window>
|
|
@ -0,0 +1,227 @@
|
|||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:AvaloniaAutoGrid;assembly=AvaloniaAutoGrid"
|
||||
Title="MainWindow"
|
||||
Height="350"
|
||||
Width="525">
|
||||
|
||||
<ScrollViewer>
|
||||
|
||||
<UniformGrid>
|
||||
|
||||
<!-- Grid of 4 colors -->
|
||||
<local:AutoGrid ColumnCount="2"
|
||||
ColumnWidth="*"
|
||||
RowDefinitions="*,*"
|
||||
ChildMargin="2"
|
||||
Margin="5">
|
||||
|
||||
<Rectangle Fill="Blue" />
|
||||
<Rectangle Fill="Red" />
|
||||
<Rectangle Fill="Green" />
|
||||
<Rectangle Fill="Yellow" />
|
||||
|
||||
</local:AutoGrid>
|
||||
|
||||
<!-- Colspan Tests (default Orientation) -->
|
||||
<local:AutoGrid ColumnCount="3"
|
||||
ColumnWidth="*"
|
||||
RowCount="2"
|
||||
RowHeight="*"
|
||||
ChildMargin="2"
|
||||
Margin="5">
|
||||
|
||||
<Rectangle Fill="Blue"
|
||||
Grid.ColumnSpan="2" />
|
||||
<Rectangle Fill="Red" />
|
||||
<Rectangle Fill="Yellow" />
|
||||
<Rectangle Fill="Green"
|
||||
Grid.ColumnSpan="2" />
|
||||
|
||||
</local:AutoGrid>
|
||||
|
||||
<!-- Colspan + Rowspan Tests (default Orientation) -->
|
||||
<local:AutoGrid ColumnCount="3"
|
||||
ColumnWidth="*"
|
||||
RowCount="2"
|
||||
RowHeight="*"
|
||||
ChildMargin="2"
|
||||
Margin="5">
|
||||
|
||||
<Rectangle Fill="Blue"
|
||||
Grid.RowSpan="2" />
|
||||
<Rectangle Fill="Red" />
|
||||
<Rectangle Fill="Yellow" />
|
||||
<Rectangle Fill="Green"
|
||||
Grid.ColumnSpan="2" />
|
||||
|
||||
</local:AutoGrid>
|
||||
|
||||
<!-- Rowspan Tests, second child (default Orientation) -->
|
||||
<local:AutoGrid ColumnCount="3"
|
||||
ColumnWidth="*"
|
||||
RowCount="2"
|
||||
RowHeight="*"
|
||||
ChildMargin="2"
|
||||
Margin="5">
|
||||
|
||||
<Rectangle Fill="Blue" />
|
||||
<Rectangle Fill="Red"
|
||||
Grid.RowSpan="2" />
|
||||
<Rectangle Fill="Yellow" />
|
||||
<Rectangle Fill="Green" />
|
||||
<Rectangle Fill="Orange" />
|
||||
|
||||
</local:AutoGrid>
|
||||
|
||||
<!-- Rowspan Tests, third child (default Orientation) -->
|
||||
<local:AutoGrid ColumnCount="3"
|
||||
ColumnWidth="*"
|
||||
RowCount="2"
|
||||
RowHeight="*"
|
||||
ChildMargin="2"
|
||||
Margin="5">
|
||||
|
||||
<Rectangle Fill="Blue" />
|
||||
<Rectangle Fill="Red" />
|
||||
<Rectangle Fill="Yellow"
|
||||
Grid.RowSpan="2" />
|
||||
<Rectangle Fill="Green" />
|
||||
<Rectangle Fill="Orange" />
|
||||
|
||||
</local:AutoGrid>
|
||||
|
||||
<!-- Rowspan Tests, sufu (default Orientation) -->
|
||||
<local:AutoGrid ColumnCount="3"
|
||||
ColumnWidth="*"
|
||||
RowCount="2"
|
||||
RowHeight="*"
|
||||
ChildMargin="2"
|
||||
Margin="5">
|
||||
|
||||
<Rectangle Fill="Blue"
|
||||
Grid.RowSpan="2" />
|
||||
<Rectangle Fill="Red" />
|
||||
<Rectangle Fill="Yellow"
|
||||
Grid.RowSpan="2" />
|
||||
<Rectangle Fill="Green" />
|
||||
|
||||
</local:AutoGrid>
|
||||
|
||||
<!-- Rowspan Tests, first column (default Orientation) -->
|
||||
<local:AutoGrid ColumnCount="3"
|
||||
ColumnWidth="*"
|
||||
RowCount="2"
|
||||
RowHeight="*"
|
||||
ChildMargin="2"
|
||||
Margin="5">
|
||||
|
||||
<Rectangle Fill="Blue" Grid.RowSpan="2" />
|
||||
<Rectangle Fill="Red" />
|
||||
<Rectangle Fill="Yellow" />
|
||||
<Rectangle Fill="Green" />
|
||||
<Rectangle Fill="Orange" />
|
||||
|
||||
</local:AutoGrid>
|
||||
|
||||
|
||||
<!-- Colspan Tests, rowspan tests (Vertical Orientation) -->
|
||||
<local:AutoGrid ColumnCount="3"
|
||||
ColumnWidth="*"
|
||||
RowCount="2"
|
||||
RowHeight="*"
|
||||
ChildMargin="2"
|
||||
Orientation="Vertical"
|
||||
Margin="5">
|
||||
|
||||
<Rectangle Fill="Blue"
|
||||
Grid.RowSpan="2" />
|
||||
<Rectangle Fill="Red" />
|
||||
<Rectangle Fill="Yellow"
|
||||
Grid.RowSpan="2" />
|
||||
<Rectangle Fill="Green" />
|
||||
<Rectangle Fill="Orange" />
|
||||
|
||||
</local:AutoGrid>
|
||||
|
||||
<!-- Colspan Tests, colspan tests (Vertical Orientation) -->
|
||||
<local:AutoGrid ColumnCount="3"
|
||||
ColumnWidth="*"
|
||||
RowCount="2"
|
||||
RowHeight="*"
|
||||
ChildMargin="7"
|
||||
Orientation="Vertical"
|
||||
Margin="5">
|
||||
|
||||
<Rectangle Fill="Blue"
|
||||
Grid.ColumnSpan="2" />
|
||||
<Rectangle Fill="Red" />
|
||||
<Rectangle Fill="Yellow"
|
||||
Grid.RowSpan="2"
|
||||
Margin="7"/>
|
||||
<Rectangle Fill="Green" />
|
||||
<Rectangle Fill="Orange" />
|
||||
|
||||
</local:AutoGrid>
|
||||
|
||||
<!-- Binding Test -->
|
||||
<local:AutoGrid RowDefinitions="25*,75*"
|
||||
ColumnDefinitions="*"
|
||||
ChildMargin="5">
|
||||
<DropDown Name="uxCombo">
|
||||
<DropDown.Items>
|
||||
<x:String>1</x:String>
|
||||
<x:String>2</x:String>
|
||||
<x:String>3</x:String>
|
||||
<x:String>4</x:String>
|
||||
</DropDown.Items>
|
||||
</DropDown>
|
||||
<local:AutoGrid ColumnCount="{Binding ElementName=uxCombo, Path=SelectedItem.Content}"
|
||||
ColumnWidth="*"
|
||||
RowHeight="*"
|
||||
RowCount="4"
|
||||
ChildMargin="1">
|
||||
|
||||
<Rectangle Fill="Blue" />
|
||||
<Rectangle Fill="Red" />
|
||||
<Rectangle Fill="Green" />
|
||||
<Rectangle Fill="Yellow" />
|
||||
|
||||
</local:AutoGrid>
|
||||
</local:AutoGrid>
|
||||
|
||||
<!-- Testing collapsed child row -->
|
||||
<local:AutoGrid ColumnCount="2"
|
||||
ColumnWidth="*"
|
||||
RowDefinitions="*,*,*"
|
||||
ChildMargin="2"
|
||||
Margin="5">
|
||||
|
||||
<Rectangle Fill="Blue" />
|
||||
<Rectangle Fill="Red" />
|
||||
<Rectangle Fill="Green" IsVisible="False" />
|
||||
<Rectangle Fill="Yellow" IsVisible="False" />
|
||||
<Rectangle Fill="Purple" />
|
||||
<Rectangle Fill="Pink" />
|
||||
|
||||
</local:AutoGrid>
|
||||
|
||||
<!-- Testing single collapsed child element -->
|
||||
<local:AutoGrid ColumnCount="2"
|
||||
ColumnWidth="*"
|
||||
RowDefinitions="*,*,*"
|
||||
ChildMargin="2"
|
||||
Margin="5">
|
||||
|
||||
<Rectangle Fill="Blue" />
|
||||
<Rectangle Fill="Red" />
|
||||
<Rectangle Fill="Green" />
|
||||
<Rectangle Fill="Yellow" IsVisible="False" />
|
||||
<Rectangle Fill="Purple" />
|
||||
<Rectangle Fill="Pink" />
|
||||
|
||||
</local:AutoGrid>
|
||||
|
||||
</UniformGrid>
|
||||
</ScrollViewer>
|
||||
</Window>
|
|
@ -0,0 +1,18 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace AutoGridExamples
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
//this.AttachDevTools();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<solution>
|
||||
<add key="disableSourceControlIntegration" value="true" />
|
||||
</solution>
|
||||
</configuration>
|
Двоичный файл не отображается.
|
@ -0,0 +1,133 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
|
||||
|
||||
<!-- Enable the restore command to run before builds -->
|
||||
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>
|
||||
|
||||
<!-- Property that enables building a package from a project -->
|
||||
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>
|
||||
|
||||
<!-- Determines if package restore consent is required to restore packages -->
|
||||
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>
|
||||
|
||||
<!-- Download NuGet.exe if it does not already exist -->
|
||||
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(PackageSources)' == '' ">
|
||||
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
|
||||
<!-- The official NuGet package source (https://nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
|
||||
<!--
|
||||
<PackageSource Include="https://nuget.org/api/v2/" />
|
||||
<PackageSource Include="https://my-nuget-source/nuget/" />
|
||||
-->
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
|
||||
<!-- Windows specific commands -->
|
||||
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
|
||||
<PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
|
||||
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
|
||||
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
|
||||
<PackagesConfig>packages.config</PackagesConfig>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- NuGet command -->
|
||||
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\NuGet.exe</NuGetExePath>
|
||||
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>
|
||||
|
||||
<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
|
||||
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>
|
||||
|
||||
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
|
||||
|
||||
<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
|
||||
<NonInteractiveSwitch Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' ">-NonInteractive</NonInteractiveSwitch>
|
||||
|
||||
<!-- Commands -->
|
||||
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir "$(SolutionDir) " </RestoreCommand>
|
||||
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties Configuration=$(Configuration) $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand>
|
||||
|
||||
<!-- We need to ensure packages are restored prior to assembly resolve -->
|
||||
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
|
||||
RestorePackages;
|
||||
$(BuildDependsOn);
|
||||
</BuildDependsOn>
|
||||
|
||||
<!-- Make the build depend on restore packages -->
|
||||
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
|
||||
$(BuildDependsOn);
|
||||
BuildPackage;
|
||||
</BuildDependsOn>
|
||||
</PropertyGroup>
|
||||
|
||||
<Target Name="CheckPrerequisites">
|
||||
<!-- Raise an error if we're unable to locate nuget.exe -->
|
||||
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
|
||||
<!--
|
||||
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
|
||||
This effectively acts as a lock that makes sure that the download operation will only happen once and all
|
||||
parallel builds will have to wait for it to complete.
|
||||
-->
|
||||
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;DownloadNuGetExe=$(DownloadNuGetExe)" />
|
||||
</Target>
|
||||
|
||||
<Target Name="_DownloadNuGet">
|
||||
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
|
||||
</Target>
|
||||
|
||||
<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
|
||||
<Exec Command="$(RestoreCommand)"
|
||||
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
|
||||
|
||||
<Exec Command="$(RestoreCommand)"
|
||||
LogStandardErrorAsError="true"
|
||||
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
|
||||
</Target>
|
||||
|
||||
<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
|
||||
<Exec Command="$(BuildCommand)"
|
||||
Condition=" '$(OS)' != 'Windows_NT' " />
|
||||
|
||||
<Exec Command="$(BuildCommand)"
|
||||
LogStandardErrorAsError="true"
|
||||
Condition=" '$(OS)' == 'Windows_NT' " />
|
||||
</Target>
|
||||
|
||||
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
|
||||
<ParameterGroup>
|
||||
<OutputFilename ParameterType="System.String" Required="true" />
|
||||
</ParameterGroup>
|
||||
<Task>
|
||||
<Reference Include="System.Core" />
|
||||
<Using Namespace="System" />
|
||||
<Using Namespace="System.IO" />
|
||||
<Using Namespace="System.Net" />
|
||||
<Using Namespace="Microsoft.Build.Framework" />
|
||||
<Using Namespace="Microsoft.Build.Utilities" />
|
||||
<Code Type="Fragment" Language="cs">
|
||||
<![CDATA[
|
||||
try {
|
||||
OutputFilename = Path.GetFullPath(OutputFilename);
|
||||
|
||||
Log.LogMessage("Downloading latest version of NuGet.exe...");
|
||||
WebClient webClient = new WebClient();
|
||||
webClient.DownloadFile("https://nuget.org/nuget.exe", OutputFilename);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Log.LogErrorFromException(ex);
|
||||
return false;
|
||||
}
|
||||
]]>
|
||||
</Code>
|
||||
</Task>
|
||||
</UsingTask>
|
||||
</Project>
|
|
@ -0,0 +1,384 @@
|
|||
// ReSharper disable UnusedMember.Global
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Layout;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
namespace AvaloniaAutoGrid
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a flexible grid area that consists of columns and rows.
|
||||
/// Depending on the orientation, either the rows or the columns are auto-generated,
|
||||
/// and the children's position is set according to their index.
|
||||
/// </summary>
|
||||
public class AutoGrid : Grid
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the child horizontal alignment.
|
||||
/// </summary>
|
||||
/// <value>The child horizontal alignment.</value>
|
||||
[Category("Layout"), Description("Presets the horizontal alignment of all child controls")]
|
||||
public HorizontalAlignment? ChildHorizontalAlignment
|
||||
{
|
||||
get => (HorizontalAlignment?)GetValue(ChildHorizontalAlignmentProperty);
|
||||
set => SetValue(ChildHorizontalAlignmentProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the child margin.
|
||||
/// </summary>
|
||||
/// <value>The child margin.</value>
|
||||
[Category("Layout"), Description("Presets the margin of all child controls")]
|
||||
public Thickness? ChildMargin
|
||||
{
|
||||
get => (Thickness?)GetValue(ChildMarginProperty);
|
||||
set => SetValue(ChildMarginProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the child vertical alignment.
|
||||
/// </summary>
|
||||
/// <value>The child vertical alignment.</value>
|
||||
[Category("Layout"), Description("Presets the vertical alignment of all child controls")]
|
||||
public VerticalAlignment? ChildVerticalAlignment
|
||||
{
|
||||
get => (VerticalAlignment?)GetValue(ChildVerticalAlignmentProperty);
|
||||
set => SetValue(ChildVerticalAlignmentProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the column count
|
||||
/// </summary>
|
||||
[Category("Layout"), Description("Defines a set number of columns")]
|
||||
public int ColumnCount
|
||||
{
|
||||
get => (int)GetValue(ColumnCountProperty);
|
||||
set => SetValue(ColumnCountProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the fixed column width
|
||||
/// </summary>
|
||||
[Category("Layout"), Description("Presets the width of all columns set using the ColumnCount property")]
|
||||
|
||||
public GridLength ColumnWidth
|
||||
{
|
||||
get => (GridLength)GetValue(ColumnWidthProperty);
|
||||
set => SetValue(ColumnWidthProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the children are automatically indexed.
|
||||
/// <remarks>
|
||||
/// The default is <c>true</c>.
|
||||
/// Note that if children are already indexed, setting this property to <c>false</c> will not remove their indices.
|
||||
/// </remarks>
|
||||
/// </summary>
|
||||
[Category("Layout"), Description("Set to false to disable the auto layout functionality")]
|
||||
public bool IsAutoIndexing
|
||||
{
|
||||
get => (bool)GetValue(IsAutoIndexingProperty);
|
||||
set => SetValue(IsAutoIndexingProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the orientation.
|
||||
/// <remarks>The default is Vertical.</remarks>
|
||||
/// </summary>
|
||||
/// <value>The orientation.</value>
|
||||
[Category("Layout"), Description("Defines the directionality of the autolayout. Use vertical for a column first layout, horizontal for a row first layout.")]
|
||||
public Orientation Orientation
|
||||
{
|
||||
get => (Orientation)GetValue(OrientationProperty);
|
||||
set => SetValue(OrientationProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of rows
|
||||
/// </summary>
|
||||
[Category("Layout"), Description("Defines a set number of rows")]
|
||||
public int RowCount
|
||||
{
|
||||
get => (int)GetValue(RowCountProperty);
|
||||
set => SetValue(RowCountProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the fixed row height
|
||||
/// </summary>
|
||||
[Category("Layout"), Description("Presets the height of all rows set using the RowCount property")]
|
||||
public GridLength RowHeight
|
||||
{
|
||||
get => (GridLength)GetValue(RowHeightProperty);
|
||||
set => SetValue(RowHeightProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the column count changed event
|
||||
/// </summary>
|
||||
public static void ColumnCountChanged(AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
if ((int)e.NewValue < 0)
|
||||
return;
|
||||
|
||||
var grid = (AutoGrid)e.Sender;
|
||||
|
||||
|
||||
// look for an existing column definition for the height
|
||||
var width = grid.ColumnWidth;
|
||||
if (!grid.IsSet(ColumnWidthProperty) && grid.ColumnDefinitions.Count > 0)
|
||||
width = grid.ColumnDefinitions[0].Width;
|
||||
|
||||
// clear and rebuild
|
||||
grid.ColumnDefinitions.Clear();
|
||||
for (var i = 0; i < (int)e.NewValue; i++)
|
||||
grid.ColumnDefinitions.Add(
|
||||
new ColumnDefinition() { Width = width });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the fixed column width changed event
|
||||
/// </summary>
|
||||
public static void FixedColumnWidthChanged(AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
var grid = (AutoGrid)e.Sender;
|
||||
|
||||
// add a default column if missing
|
||||
if (grid.ColumnDefinitions.Count == 0)
|
||||
grid.ColumnDefinitions.Add(new ColumnDefinition());
|
||||
|
||||
// set all existing columns to this width
|
||||
foreach (var t in grid.ColumnDefinitions)
|
||||
t.Width = (GridLength)e.NewValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the fixed row height changed event
|
||||
/// </summary>
|
||||
public static void FixedRowHeightChanged(AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
var grid = (AutoGrid)e.Sender;
|
||||
|
||||
// add a default row if missing
|
||||
if (grid.RowDefinitions.Count == 0)
|
||||
grid.RowDefinitions.Add(new RowDefinition());
|
||||
|
||||
// set all existing rows to this height
|
||||
foreach (var t in grid.RowDefinitions)
|
||||
t.Height = (GridLength)e.NewValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the row count changed event
|
||||
/// </summary>
|
||||
public static void RowCountChanged(AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
if ((int)e.NewValue < 0)
|
||||
return;
|
||||
|
||||
var grid = (AutoGrid)e.Sender;
|
||||
|
||||
// look for an existing row to get the height
|
||||
var height = grid.RowHeight;
|
||||
if (!grid.IsSet(RowHeightProperty) && grid.RowDefinitions.Count > 0)
|
||||
height = grid.RowDefinitions[0].Height;
|
||||
|
||||
// clear and rebuild
|
||||
grid.RowDefinitions.Clear();
|
||||
for (var i = 0; i < (int)e.NewValue; i++)
|
||||
grid.RowDefinitions.Add(
|
||||
new RowDefinition() { Height = height });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when [child horizontal alignment changed].
|
||||
/// </summary>
|
||||
private static void OnChildHorizontalAlignmentChanged(AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
var grid = (AutoGrid)e.Sender;
|
||||
foreach (var child in grid.Children)
|
||||
{
|
||||
child.SetValue(HorizontalAlignmentProperty,
|
||||
grid.ChildHorizontalAlignment ?? AvaloniaProperty.UnsetValue);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when [child layout changed].
|
||||
/// </summary>
|
||||
private static void OnChildMarginChanged(AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
var grid = (AutoGrid)e.Sender;
|
||||
foreach (var child in grid.Children)
|
||||
{
|
||||
child.SetValue(MarginProperty, grid.ChildMargin ?? AvaloniaProperty.UnsetValue);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when [child vertical alignment changed].
|
||||
/// </summary>
|
||||
private static void OnChildVerticalAlignmentChanged(AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
var grid = (AutoGrid)e.Sender;
|
||||
foreach (var child in grid.Children)
|
||||
{
|
||||
child.SetValue(VerticalAlignmentProperty, grid.ChildVerticalAlignment ?? AvaloniaProperty.UnsetValue);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply child margins and layout effects such as alignment
|
||||
/// </summary>
|
||||
private void ApplyChildLayout(Control child)
|
||||
{
|
||||
if (ChildMargin != null)
|
||||
{
|
||||
child.SetIfDefault(MarginProperty, ChildMargin.Value);
|
||||
}
|
||||
if (ChildHorizontalAlignment != null)
|
||||
{
|
||||
child.SetIfDefault(HorizontalAlignmentProperty, ChildHorizontalAlignment.Value);
|
||||
}
|
||||
if (ChildVerticalAlignment != null)
|
||||
{
|
||||
child.SetIfDefault(VerticalAlignmentProperty, ChildVerticalAlignment.Value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clamp a value to its maximum.
|
||||
/// </summary>
|
||||
private int Clamp(int value, int max)
|
||||
{
|
||||
return (value > max) ? max : value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform the grid layout of row and column indexes
|
||||
/// </summary>
|
||||
private void PerformLayout()
|
||||
{
|
||||
var fillRowFirst = Orientation == Orientation.Horizontal;
|
||||
var rowCount = RowDefinitions.Count;
|
||||
var colCount = ColumnDefinitions.Count;
|
||||
|
||||
if (rowCount == 0 || colCount == 0)
|
||||
return;
|
||||
|
||||
var position = 0;
|
||||
var skip = new bool[rowCount, colCount];
|
||||
foreach (var child in Children.OfType<Control>())
|
||||
{
|
||||
var childIsCollapsed = !child.IsVisible;
|
||||
if (IsAutoIndexing && !childIsCollapsed)
|
||||
{
|
||||
if (fillRowFirst)
|
||||
{
|
||||
var row = Clamp(position / colCount, rowCount - 1);
|
||||
var col = Clamp(position % colCount, colCount - 1);
|
||||
if (skip[row, col])
|
||||
{
|
||||
position++;
|
||||
row = (position / colCount);
|
||||
col = (position % colCount);
|
||||
}
|
||||
|
||||
SetRow(child, row);
|
||||
SetColumn(child, col);
|
||||
position += GetColumnSpan(child);
|
||||
|
||||
var offset = GetRowSpan(child) - 1;
|
||||
while (offset > 0)
|
||||
{
|
||||
skip[row + offset--, col] = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var row = Clamp(position % rowCount, rowCount - 1);
|
||||
var col = Clamp(position / rowCount, colCount - 1);
|
||||
if (skip[row, col])
|
||||
{
|
||||
position++;
|
||||
row = position % rowCount;
|
||||
col = position / rowCount;
|
||||
}
|
||||
|
||||
SetRow(child, row);
|
||||
SetColumn(child, col);
|
||||
position += GetRowSpan(child);
|
||||
|
||||
var offset = GetColumnSpan(child) - 1;
|
||||
while (offset > 0)
|
||||
{
|
||||
skip[row, col + offset--] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ApplyChildLayout(child);
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly AvaloniaProperty ChildHorizontalAlignmentProperty =
|
||||
AvaloniaProperty.Register<AutoGrid, HorizontalAlignment?>("ChildHorizontalAlignment");
|
||||
|
||||
public static readonly AvaloniaProperty ChildMarginProperty =
|
||||
AvaloniaProperty.Register<AutoGrid, Thickness?>("ChildMargin");
|
||||
|
||||
public static readonly AvaloniaProperty ChildVerticalAlignmentProperty =
|
||||
AvaloniaProperty.Register<AutoGrid, VerticalAlignment?>("ChildVerticalAlignment");
|
||||
|
||||
public static readonly AvaloniaProperty ColumnCountProperty =
|
||||
AvaloniaProperty.RegisterAttached<Control, int>("ColumnCount", typeof(AutoGrid), 1);
|
||||
|
||||
public static readonly AvaloniaProperty ColumnWidthProperty =
|
||||
AvaloniaProperty.RegisterAttached<Control, GridLength>("ColumnWidth", typeof(AutoGrid), GridLength.Auto);
|
||||
|
||||
public static readonly AvaloniaProperty IsAutoIndexingProperty =
|
||||
AvaloniaProperty.Register<AutoGrid, bool>("IsAutoIndexing", true);
|
||||
|
||||
public static readonly AvaloniaProperty OrientationProperty =
|
||||
AvaloniaProperty.Register<AutoGrid, Orientation>("Orientation");
|
||||
|
||||
public static readonly AvaloniaProperty RowCountProperty =
|
||||
AvaloniaProperty.RegisterAttached<Control, int>("RowCount", typeof(AutoGrid), 1);
|
||||
|
||||
public static readonly AvaloniaProperty RowHeightProperty =
|
||||
AvaloniaProperty.RegisterAttached<Control, GridLength>("RowHeight", typeof(AutoGrid), GridLength.Auto);
|
||||
|
||||
static AutoGrid()
|
||||
{
|
||||
AffectsMeasure<AutoGrid>(ChildHorizontalAlignmentProperty, ChildMarginProperty,
|
||||
ChildVerticalAlignmentProperty, ColumnCountProperty, ColumnWidthProperty, IsAutoIndexingProperty, OrientationProperty,
|
||||
RowHeightProperty);
|
||||
|
||||
ChildHorizontalAlignmentProperty.Changed.Subscribe(OnChildHorizontalAlignmentChanged);
|
||||
ChildMarginProperty.Changed.Subscribe(OnChildMarginChanged);
|
||||
ChildVerticalAlignmentProperty.Changed.Subscribe(OnChildVerticalAlignmentChanged);
|
||||
ColumnCountProperty.Changed.Subscribe(ColumnCountChanged);
|
||||
RowCountProperty.Changed.Subscribe(RowCountChanged);
|
||||
ColumnWidthProperty.Changed.Subscribe(FixedColumnWidthChanged);
|
||||
RowHeightProperty.Changed.Subscribe(FixedRowHeightChanged);
|
||||
}
|
||||
#region Overrides
|
||||
|
||||
/// <summary>
|
||||
/// Measures the children of a <see cref="T:System.Windows.Controls.Grid"/> in anticipation of arranging them during the <see cref="M:ArrangeOverride"/> pass.
|
||||
/// </summary>
|
||||
/// <param name="constraint">Indicates an upper limit size that should not be exceeded.</param>
|
||||
/// <returns>
|
||||
/// <see cref="Size"/> that represents the required size to arrange child content.
|
||||
/// </returns>
|
||||
protected override Size MeasureOverride(Size constraint)
|
||||
{
|
||||
PerformLayout();
|
||||
return base.MeasureOverride(constraint);
|
||||
}
|
||||
|
||||
#endregion Overrides
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="0.7.1-build1036-beta" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,39 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Data;
|
||||
|
||||
namespace AvaloniaAutoGrid
|
||||
{
|
||||
using System.Windows;
|
||||
|
||||
static class DependencyExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the value of the <paramref name="property"/> only if it hasn't been explicitly set.
|
||||
/// </summary>
|
||||
public static bool SetIfDefault<T>(this AvaloniaObject o, AvaloniaProperty property, T value)
|
||||
{
|
||||
|
||||
var diag = Avalonia.Diagnostics.AvaloniaObjectExtensions.GetDiagnostic(o, property);
|
||||
if (diag.Priority == BindingPriority.Unset)
|
||||
{
|
||||
o.SetValue(property, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
o.SetValue(property, value);
|
||||
return true;
|
||||
//TODO: Implement in AvaloniaUI
|
||||
/*
|
||||
if (AvaloniaPropertyHelper.GetValueSource(o, property).BaseValueSource == BaseValueSource.Default)
|
||||
{
|
||||
o.SetValue(property, value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;*/
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче