12 changed files with 184 additions and 301 deletions
@ -0,0 +1,41 @@ |
|||
namespace ControlCatalog.Models |
|||
{ |
|||
public class Country |
|||
{ |
|||
public string Name { get; private set; } |
|||
public string Region { get; private set; } |
|||
public int Population { get; private set; } |
|||
//Square Miles
|
|||
public int Area { get; private set; } |
|||
//Per Square Mile
|
|||
public double PopulationDensity { get; private set; } |
|||
//Coast / Area
|
|||
public double CoastLine { get; private set; } |
|||
public double? NetMigration { get; private set; } |
|||
//per 1000 births
|
|||
public double? InfantMortality { get; private set; } |
|||
public int GDP { get; private set; } |
|||
public double? LiteracyPercent { get; private set; } |
|||
//per 1000
|
|||
public double? Phones { get; private set; } |
|||
public double? BirthRate { get; private set; } |
|||
public double? DeathRate { get; private set; } |
|||
|
|||
public Country(string name, string region, int population, int area, double density, double coast, double? migration, |
|||
double? infantMorality, int gdp, double? literacy, double? phones, double? birth, double? death) |
|||
{ |
|||
Name = name; |
|||
Region = region; |
|||
Population = population; |
|||
Area = area; |
|||
PopulationDensity = density; |
|||
CoastLine = coast; |
|||
NetMigration = migration; |
|||
InfantMortality = infantMorality; |
|||
GDP = gdp; |
|||
LiteracyPercent = literacy; |
|||
BirthRate = birth; |
|||
DeathRate = death; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
using Avalonia; |
|||
using Avalonia.Controls; |
|||
using Avalonia.Markup.Xaml; |
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel; |
|||
using System.Globalization; |
|||
using System.Linq; |
|||
using Avalonia.Data.Converters; |
|||
using Avalonia.Media; |
|||
|
|||
namespace ControlCatalog.Models |
|||
{ |
|||
public class GDPValueConverter : IValueConverter |
|||
{ |
|||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) |
|||
{ |
|||
if (value is int gdp) |
|||
{ |
|||
if (gdp <= 5000) |
|||
return Brushes.Orange; |
|||
else if (gdp <= 10000) |
|||
return Brushes.Yellow; |
|||
else |
|||
return Brushes.LightGreen; |
|||
} |
|||
|
|||
return value; |
|||
} |
|||
|
|||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
<UserControl xmlns="https://github.com/avaloniaui" |
|||
xmlns:local="clr-namespace:ControlCatalog.Models;assembly=ControlCatalog" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
|||
<UserControl.Resources> |
|||
<local:GDPValueConverter x:Key="GDPConverter" /> |
|||
</UserControl.Resources> |
|||
<UserControl.Styles> |
|||
<Style Selector="DataGridCell.gdp"> |
|||
<Setter Property="FontWeight" Value="Bold" /> |
|||
<Setter Property="Background" Value="{Binding Path=GDP, Mode=OneWay, Converter={StaticResource GDPConverter}}" /> |
|||
</Style> |
|||
</UserControl.Styles> |
|||
<TabControl> |
|||
<TabItem Header="DataGrid"> |
|||
<DataGrid Name="dataGrid1" Margin="12" CanUserResizeColumns="True" CanUserReorderColumns="True"> |
|||
<DataGrid.Columns> |
|||
<DataGridTextColumn Header="Country" Binding="{Binding Name}" Width="6*" /> |
|||
<DataGridTextColumn Header="Region" Binding="{Binding Region}" Width="4*" /> |
|||
<DataGridTextColumn Header="Population" Binding="{Binding Population}" Width="3*" /> |
|||
<DataGridTextColumn Header="Area" Binding="{Binding Area}" Width="3*" /> |
|||
<DataGridTextColumn Header="GDP" Binding="{Binding GDP}" Width="3*" CellStyleClasses="gdp" /> |
|||
</DataGrid.Columns> |
|||
</DataGrid> |
|||
</TabItem> |
|||
<TabItem Header="Grouping"> |
|||
<DataGrid Name="dataGridGrouping" Margin="12"> |
|||
<DataGrid.Columns> |
|||
<DataGridTextColumn Header="Country" Binding="{Binding Name}" Width="6*" /> |
|||
<DataGridTextColumn Header="Region" Binding="{Binding Region}" Width="4*" /> |
|||
<DataGridTextColumn Header="Population" Binding="{Binding Population}" Width="3*" /> |
|||
<DataGridTextColumn Header="Area" Binding="{Binding Area}" Width="3*" /> |
|||
<DataGridTextColumn Header="GDP" Binding="{Binding GDP}" Width="3*" /> |
|||
</DataGrid.Columns> |
|||
</DataGrid> |
|||
</TabItem> |
|||
<TabItem Header="Editable"> |
|||
<Grid RowDefinitions="*,Auto"> |
|||
<DataGrid Name="dataGridEdit" Margin="12" Grid.Row="0"> |
|||
<DataGrid.Columns> |
|||
<DataGridTextColumn Header="First Name" Binding="{Binding FirstName}" Width="2*" /> |
|||
<DataGridTextColumn Header="Last" Binding="{Binding LastName}" Width="*" /> |
|||
</DataGrid.Columns> |
|||
</DataGrid> |
|||
<Button Grid.Row="1" Name="btnAdd" Margin="12,0,12,12" Content="Add" HorizontalAlignment="Right" /> |
|||
</Grid> |
|||
</TabItem> |
|||
</TabControl> |
|||
</UserControl> |
|||
@ -0,0 +1,52 @@ |
|||
using System.Collections.Generic; |
|||
using Avalonia.Controls; |
|||
using Avalonia.Markup.Xaml; |
|||
using ControlCatalog.Models; |
|||
using Avalonia.Collections; |
|||
|
|||
namespace ControlCatalog.Pages |
|||
{ |
|||
public class DataGridPage : UserControl |
|||
{ |
|||
public DataGridPage() |
|||
{ |
|||
this.InitializeComponent(); |
|||
var dg1 = this.FindControl<DataGrid>("dataGrid1"); |
|||
dg1.IsReadOnly = true; |
|||
|
|||
var collectionView1 = new CollectionViewBase(Countries.All); |
|||
//collectionView.GroupDescriptions.Add(new PathGroupDescription("Region"));
|
|||
|
|||
dg1.Items = collectionView1; |
|||
|
|||
var dg2 = this.FindControl<DataGrid>("dataGridGrouping"); |
|||
dg2.IsReadOnly = true; |
|||
|
|||
var collectionView2 = new CollectionViewBase(Countries.All); |
|||
collectionView2.GroupDescriptions.Add(new PathGroupDescription("Region")); |
|||
|
|||
dg2.Items = collectionView2; |
|||
|
|||
var dg3 = this.FindControl<DataGrid>("dataGridEdit"); |
|||
dg3.IsReadOnly = false; |
|||
|
|||
var items = new List<Person> |
|||
{ |
|||
new Person { FirstName = "John", LastName = "Doe" }, |
|||
new Person { FirstName = "Elizabeth", LastName = "Thomas" }, |
|||
new Person { FirstName = "Zack", LastName = "Ward" } |
|||
}; |
|||
var collectionView3 = new CollectionViewBase(items); |
|||
|
|||
dg3.Items = collectionView3; |
|||
|
|||
var addButton = this.FindControl<Button>("btnAdd"); |
|||
addButton.Click += (a, b) => collectionView3.AddNew(); |
|||
} |
|||
|
|||
private void InitializeComponent() |
|||
{ |
|||
AvaloniaXamlLoader.Load(this); |
|||
} |
|||
} |
|||
} |
|||
@ -1,8 +0,0 @@ |
|||
<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"/> |
|||
<StyleInclude Source="resm:Avalonia.DataGrid.Themes.Default.DefaultTheme.xaml?assembly=Avalonia.DataGrid.Themes.Default"/> |
|||
</Application.Styles> |
|||
</Application> |
|||
@ -1,13 +0,0 @@ |
|||
using Avalonia; |
|||
using Avalonia.Markup.Xaml; |
|||
|
|||
namespace DataGridSample |
|||
{ |
|||
public class App : Application |
|||
{ |
|||
public override void Initialize() |
|||
{ |
|||
AvaloniaXamlLoader.Load(this); |
|||
} |
|||
} |
|||
} |
|||
@ -1,22 +0,0 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
<PropertyGroup> |
|||
<OutputType>Exe</OutputType> |
|||
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<Compile Update="**\*.xaml.cs"> |
|||
<DependentUpon>%(Filename)</DependentUpon> |
|||
</Compile> |
|||
<EmbeddedResource Include="**\*.xaml"> |
|||
<SubType>Designer</SubType> |
|||
</EmbeddedResource> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<PackageReference Include="Avalonia" Version="0.6.2-build5800-beta" /> |
|||
<PackageReference Include="Avalonia.Desktop" Version="0.6.2-build5800-beta" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\src\Avalonia.DataGrid.Themes.Default\Avalonia.DataGrid.Themes.Default.csproj" /> |
|||
<ProjectReference Include="..\..\src\Avalonia.DataGrid\Avalonia.DataGrid.csproj" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
@ -1,125 +0,0 @@ |
|||
<Window xmlns="https://github.com/avaloniaui" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
xmlns:dg="clr-namespace:Avalonia.Controls;assembly=Avalonia.DataGrid" |
|||
xmlns:local="clr-namespace:DataGridSample;assembly=DataGridSample" |
|||
Title="DataGridSample" |
|||
Width="800" |
|||
Height="600"> |
|||
|
|||
<Window.Resources> |
|||
<local:GDPValueConverter |
|||
x:Key="GDPConverter"/> |
|||
</Window.Resources> |
|||
|
|||
<Window.Styles> |
|||
<Style Selector="dg|DataGridCell.gdp"> |
|||
<Setter |
|||
Property="FontWeight" |
|||
Value="Bold"/> |
|||
<Setter |
|||
Property="Background" |
|||
Value="{Binding Path=GDP, Mode=OneWay, Converter={StaticResource GDPConverter}}"/> |
|||
</Style> |
|||
</Window.Styles> |
|||
|
|||
<TabControl> |
|||
<TabItem Header="DataGrid"> |
|||
<dg:DataGrid |
|||
Name="dataGrid1" |
|||
Margin="12" |
|||
CanUserResizeColumns="True" |
|||
CanUserReorderColumns="True"> |
|||
|
|||
<dg:DataGrid.Columns> |
|||
|
|||
<dg:DataGridTextColumn |
|||
Header="Country" |
|||
Binding="{Binding Name}" |
|||
Width="6*" /> |
|||
<dg:DataGridTextColumn |
|||
Header="Region" |
|||
Binding="{Binding Region}" |
|||
Width="4*"/> |
|||
<dg:DataGridTextColumn |
|||
Header="Population" |
|||
Binding="{Binding Population}" |
|||
Width="3*"/> |
|||
<dg:DataGridTextColumn |
|||
Header="Area" |
|||
Binding="{Binding Area}" |
|||
Width="3*"/> |
|||
<dg:DataGridTextColumn |
|||
Header="GDP" |
|||
Binding="{Binding GDP}" |
|||
Width="3*" |
|||
CellStyleClasses="gdp"/> |
|||
|
|||
</dg:DataGrid.Columns> |
|||
|
|||
</dg:DataGrid> |
|||
</TabItem> |
|||
|
|||
<TabItem Header="Grouping"> |
|||
<dg:DataGrid |
|||
Name="dataGridGrouping" |
|||
Margin="12"> |
|||
|
|||
<dg:DataGrid.Columns> |
|||
|
|||
<dg:DataGridTextColumn |
|||
Header="Country" |
|||
Binding="{Binding Name}" |
|||
Width="6*" /> |
|||
<dg:DataGridTextColumn |
|||
Header="Region" |
|||
Binding="{Binding Region}" |
|||
Width="4*"/> |
|||
<dg:DataGridTextColumn |
|||
Header="Population" |
|||
Binding="{Binding Population}" |
|||
Width="3*"/> |
|||
<dg:DataGridTextColumn |
|||
Header="Area" |
|||
Binding="{Binding Area}" |
|||
Width="3*"/> |
|||
<dg:DataGridTextColumn |
|||
Header="GDP" |
|||
Binding="{Binding GDP}" |
|||
Width="3*"/> |
|||
|
|||
</dg:DataGrid.Columns> |
|||
|
|||
</dg:DataGrid> |
|||
</TabItem> |
|||
|
|||
<TabItem Header="Editable"> |
|||
<Grid |
|||
RowDefinitions="*,Auto"> |
|||
<dg:DataGrid |
|||
Name="dataGridEdit" |
|||
Margin="12" |
|||
Grid.Row="0"> |
|||
|
|||
<dg:DataGrid.Columns> |
|||
<dg:DataGridTextColumn |
|||
Header="First Name" |
|||
Binding="{Binding FirstName}" |
|||
Width="2*" /> |
|||
<dg:DataGridTextColumn |
|||
Header="Last" |
|||
Binding="{Binding LastName}" |
|||
Width="*"/> |
|||
</dg:DataGrid.Columns> |
|||
</dg:DataGrid> |
|||
<Button |
|||
Grid.Row="1" |
|||
Name="btnAdd" |
|||
Margin="12,0,12,12" |
|||
Content="Add" |
|||
HorizontalAlignment="Right"/> |
|||
</Grid> |
|||
</TabItem> |
|||
|
|||
</TabControl> |
|||
|
|||
</Window> |
|||
@ -1,19 +0,0 @@ |
|||
using System; |
|||
using Avalonia; |
|||
using Avalonia.Logging.Serilog; |
|||
|
|||
namespace DataGridSample |
|||
{ |
|||
class Program |
|||
{ |
|||
static void Main(string[] args) |
|||
{ |
|||
BuildAvaloniaApp().Start<MainWindow>(); |
|||
} |
|||
|
|||
public static AppBuilder BuildAvaloniaApp() |
|||
=> AppBuilder.Configure<App>() |
|||
.UsePlatformDetect() |
|||
.LogToDebug(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue