From a827ce0ab4c8c5d1b08ec8dfe4074e2f2681533b Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sat, 17 Nov 2018 20:10:15 +0800 Subject: [PATCH] Integrate DataGridSample into ControlCatalog --- samples/ControlCatalog/MainView.xaml | 1 + .../Models}/Countries.cs | 41 +----- samples/ControlCatalog/Models/Country.cs | 41 ++++++ .../Models/GDPValueConverter.cs | 37 ++++++ .../Models/Person.cs} | 78 +---------- .../ControlCatalog/Pages/DataGridPage.xaml | 48 +++++++ .../ControlCatalog/Pages/DataGridPage.xaml.cs | 52 ++++++++ samples/DataGridSample/App.xaml | 8 -- samples/DataGridSample/App.xaml.cs | 13 -- samples/DataGridSample/DataGridSample.csproj | 22 --- samples/DataGridSample/MainWindow.xaml | 125 ------------------ samples/DataGridSample/Program.cs | 19 --- 12 files changed, 184 insertions(+), 301 deletions(-) rename samples/{DataGridSample => ControlCatalog/Models}/Countries.cs (97%) create mode 100644 samples/ControlCatalog/Models/Country.cs create mode 100644 samples/ControlCatalog/Models/GDPValueConverter.cs rename samples/{DataGridSample/MainWindow.xaml.cs => ControlCatalog/Models/Person.cs} (52%) create mode 100644 samples/ControlCatalog/Pages/DataGridPage.xaml create mode 100644 samples/ControlCatalog/Pages/DataGridPage.xaml.cs delete mode 100644 samples/DataGridSample/App.xaml delete mode 100644 samples/DataGridSample/App.xaml.cs delete mode 100644 samples/DataGridSample/DataGridSample.csproj delete mode 100644 samples/DataGridSample/MainWindow.xaml delete mode 100644 samples/DataGridSample/Program.cs diff --git a/samples/ControlCatalog/MainView.xaml b/samples/ControlCatalog/MainView.xaml index ec3bf799b4..d87b8d32a7 100644 --- a/samples/ControlCatalog/MainView.xaml +++ b/samples/ControlCatalog/MainView.xaml @@ -14,6 +14,7 @@ + diff --git a/samples/DataGridSample/Countries.cs b/samples/ControlCatalog/Models/Countries.cs similarity index 97% rename from samples/DataGridSample/Countries.cs rename to samples/ControlCatalog/Models/Countries.cs index fc1b3ac5b6..fb8aaccd5d 100644 --- a/samples/DataGridSample/Countries.cs +++ b/samples/ControlCatalog/Models/Countries.cs @@ -3,47 +3,8 @@ using System.Collections.Generic; using System.Text; using System.Linq; -namespace DataGridSample +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; - } - } - public static class Countries { static IEnumerable GetCountries() diff --git a/samples/ControlCatalog/Models/Country.cs b/samples/ControlCatalog/Models/Country.cs new file mode 100644 index 0000000000..072383a31c --- /dev/null +++ b/samples/ControlCatalog/Models/Country.cs @@ -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; + } + } +} diff --git a/samples/ControlCatalog/Models/GDPValueConverter.cs b/samples/ControlCatalog/Models/GDPValueConverter.cs new file mode 100644 index 0000000000..f7975ac604 --- /dev/null +++ b/samples/ControlCatalog/Models/GDPValueConverter.cs @@ -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(); + } + } +} \ No newline at end of file diff --git a/samples/DataGridSample/MainWindow.xaml.cs b/samples/ControlCatalog/Models/Person.cs similarity index 52% rename from samples/DataGridSample/MainWindow.xaml.cs rename to samples/ControlCatalog/Models/Person.cs index 6a172f3afc..4248cb8056 100644 --- a/samples/DataGridSample/MainWindow.xaml.cs +++ b/samples/ControlCatalog/Models/Person.cs @@ -1,4 +1,4 @@ -using Avalonia; +using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; using System; @@ -9,9 +9,9 @@ using System.Globalization; using System.Linq; using Avalonia.Media; -namespace DataGridSample +namespace ControlCatalog.Models { - public class Person : System.ComponentModel.INotifyDataErrorInfo, INotifyPropertyChanged + public class Person : INotifyDataErrorInfo, INotifyPropertyChanged { string _firstName; string _lastName; @@ -95,74 +95,4 @@ namespace DataGridSample return null; } } - - public class GDPValueConverter : Avalonia.Data.Converters.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(); - } - } - - public class MainWindow : Window - { - public MainWindow() - { - InitializeComponent(); -#if DEBUG - this.AttachDevTools(); -#endif - var dg1 = this.FindControl("dataGrid1"); - dg1.IsReadOnly = true; - - var collectionView1 = new Avalonia.Collections.CollectionViewBase(Countries.All); - //collectionView.GroupDescriptions.Add(new Avalonia.Collections.PathGroupDescription("Region")); - - dg1.Items = collectionView1; - - var dg2 = this.FindControl("dataGridGrouping"); - dg2.IsReadOnly = true; - - var collectionView2 = new Avalonia.Collections.CollectionViewBase(Countries.All); - collectionView2.GroupDescriptions.Add(new Avalonia.Collections.PathGroupDescription("Region")); - - dg2.Items = collectionView2; - - var dg3 = this.FindControl("dataGridEdit"); - dg3.IsReadOnly = false; - - var items = new List - { - new Person { FirstName = "John", LastName = "Doe" }, - new Person { FirstName = "Elizabeth", LastName = "Thomas" }, - new Person { FirstName = "Zack", LastName = "Ward" } - }; - var collectionView3 = new Avalonia.Collections.CollectionViewBase(items); - - dg3.Items = collectionView3; - - var addButton = this.FindControl