Skip to content

Commit

Permalink
Merge pull request #1003 from unoplatform/dev/doti/WCT-DataGrid
Browse files Browse the repository at this point in the history
feat: Add WCT `DataGrid` sample
  • Loading branch information
MartinZikmund authored Sep 25, 2023
2 parents 88e2829 + ac1ce55 commit 7efa791
Show file tree
Hide file tree
Showing 13 changed files with 685 additions and 0 deletions.
1 change: 1 addition & 0 deletions Uno.Gallery/Uno.Gallery.Mobile/Uno.Gallery.Mobile.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

<ItemGroup>
<PackageReference Include="Uno.CommunityToolkit.WinUI.UI.Controls" Version="7.1.200-dev.13.gef3f523648" />
<PackageReference Include="Uno.CommunityToolkit.WinUI.UI.Controls.DataGrid" Version="7.1.200-dev.13.gef3f523648" />
<PackageReference Include="Uno.Cupertino.WinUI" Version="4.0.0-dev.126" />
<PackageReference Include="Uno.Extensions.Logging.OSLog" Version="1.6.0-dev.2" />
<PackageReference Include="Uno.Fonts.Fluent" Version="2.3.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.UI.Xaml.Data;
using System;

namespace Uno.Gallery.Converters;

public class DateTimeToDateTimeOffsetConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
DateTime date = (DateTime)value;
return new DateTimeOffset(date);
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
DateTimeOffset dateTimeOffset = (DateTimeOffset)value;
return dateTimeOffset.DateTime;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.UI;
using Microsoft.UI.Xaml.Data;
using System;
using System.Linq;
using System.Reflection;
using Windows.UI;

namespace Uno.Gallery.Converters;

public class FromValueToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is Color color)
{
// Use reflection to get the name of the color
PropertyInfo colorProperty = typeof(Colors).GetRuntimeProperties().FirstOrDefault(p => ((Color)p.GetValue(null)).Equals(color));
if (colorProperty != null)
{
return colorProperty.Name;
}
}

return null;
}

public object ConvertBack(object value, Type targetType, object parameter, string language) => throw new NotSupportedException("Only one-way conversion is supported.");
}
83 changes: 83 additions & 0 deletions Uno.Gallery/Uno.Gallery.Shared/Entities/Data/Plant.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using static Uno.Gallery.Entities.Data.Plant;

namespace Uno.Gallery.Entities.Data;

public class Plant : IComparable
{
public Plant(
string plantName,
int plantsCount,
FruitOrVegetableEnum fruitOrVegetable,
DateTime plantDate,
bool isWatered)
{
PlantName = plantName;
PlantsCount = plantsCount;
FruitOrVegetable = fruitOrVegetable;
PlantDate = plantDate;
IsWatered = isWatered;
}

public string PlantName { get; set; }
public int PlantsCount { get; set; }
public enum FruitOrVegetableEnum { Fruit, Vegetable }
public FruitOrVegetableEnum FruitOrVegetable { get; set; }
public DateTime PlantDate { get; set; }
public bool IsWatered { get; set; }

public IEnumerable<FruitOrVegetableEnum> FruitOrVegetableEnumValues { get; } =
Enum.GetValues(typeof(FruitOrVegetableEnum)).Cast<FruitOrVegetableEnum>();

public int CompareTo(object obj)
{
if (obj == null)
return 1;

if (obj is Plant otherPlant)
{
return PlantName.CompareTo(otherPlant.PlantName);
}
else
{
throw new ArgumentException("Object is not a Plant");
}
}
}

public class PlantCollection : List<Plant>
{
public PlantCollection() : base(GetPlants()) { }

private static IEnumerable<Plant> GetPlants()
{
yield return new Plant("Tomato", 12, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 5, 29), true);
yield return new Plant("Cucumber", 10, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 6, 15), true);
yield return new Plant("Bell Pepper", 15, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 4, 15), false);
yield return new Plant("Lettuce", 8, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 4, 1), true);
yield return new Plant("Strawberry", 35, FruitOrVegetableEnum.Fruit, new DateTime(2021, 5, 1), true);
yield return new Plant("Carrot", 5, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 3, 15), false);
yield return new Plant("Watermelon", 1, FruitOrVegetableEnum.Fruit, new DateTime(2021, 6, 1), true);
yield return new Plant("Blueberries", 31, FruitOrVegetableEnum.Fruit, new DateTime(2021, 6, 20), true);
yield return new Plant("Eggplant", 7, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 5, 10), false);
yield return new Plant("Broccoli", 9, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 4, 20), false);
yield return new Plant("Raspberry", 18, FruitOrVegetableEnum.Fruit, new DateTime(2021, 5, 25), false);
yield return new Plant("Pumpkin", 3, FruitOrVegetableEnum.Fruit, new DateTime(2021, 6, 10), true);
yield return new Plant("Green Beans", 50, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 5, 5), true);
yield return new Plant("Kale", 10, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 4, 15), true);
yield return new Plant("Grapes", 25, FruitOrVegetableEnum.Fruit, new DateTime(2021, 9, 1), true);
yield return new Plant("Potato", 6, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 10, 15), false);
yield return new Plant("Orange", 20, FruitOrVegetableEnum.Fruit, new DateTime(2021, 11, 1), true);
yield return new Plant("Zucchini", 11, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 8, 20), false);
yield return new Plant("Apple", 30, FruitOrVegetableEnum.Fruit, new DateTime(2021, 10, 1), true);
yield return new Plant("Spinach", 5, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 7, 15), true);
yield return new Plant("Pear", 15, FruitOrVegetableEnum.Fruit, new DateTime(2021, 8, 1), true);
yield return new Plant("Celery", 7, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 9, 10), true);
yield return new Plant("Pineapple", 2, FruitOrVegetableEnum.Fruit, new DateTime(2021, 12, 1), true);
yield return new Plant("Cherry", 40, FruitOrVegetableEnum.Fruit, new DateTime(2021, 6, 1), true);
yield return new Plant("Mango", 8, FruitOrVegetableEnum.Fruit, new DateTime(2021, 9, 15), true);
yield return new Plant("Cabbage", 12, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 11, 15), true);
}
}
3 changes: 3 additions & 0 deletions Uno.Gallery/Uno.Gallery.Shared/Entities/SampleCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ public enum SampleCategory

[SampleCategoryInfo("\uF0B4", "Toolkit")]
Toolkit,

[SampleCategoryInfo("\uE821", "Community Toolkit")]
CommunityToolkit,
}
}
8 changes: 8 additions & 0 deletions Uno.Gallery/Uno.Gallery.Shared/Uno.Gallery.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Controls\ContentPageLayout.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\OverviewSampleView.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\SamplePageLayout.Properties.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\DateTimeToDateTimeOffsetConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\DebugConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\EnumDescriptionConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\EnumDesignConverter.cs" />
Expand All @@ -154,11 +155,13 @@
<Compile Include="$(MSBuildThisFileDirectory)Controls\FluentColorAccentView.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\ThreeColorPaletteView.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\FromColorBrushToHexConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\FromValueToStringConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\HexToColorConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\RandomColorConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\SecretConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Deeplinking\BranchService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Domain\AnalyticsService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Entities\Data\Plant.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Entities\Data\TreeItem.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Entities\Data\Folder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Entities\SampleCategoryInfoAttribute.cs" />
Expand All @@ -182,12 +185,17 @@
<Compile Include="$(MSBuildThisFileDirectory)Selectors\NeumorphicTemplateSelector.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Command.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\ViewModelBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Views\SamplePages\DataGridSamplePage.xaml.cs" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="$(MSBuildThisFileDirectory)App.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</ApplicationDefinition>
<Page Include="$(MSBuildThisFileDirectory)Views\SamplePages\DataGridSamplePage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<_Globbled_Page Include="$(MSBuildThisFileDirectory)**/*.xaml" Exclude="@(Page);@(ApplicationDefinition)">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
9 changes: 9 additions & 0 deletions Uno.Gallery/Uno.Gallery.Shared/Uno.Gallery.Shared.shproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@
<PropertyGroup />
<Import Project="Uno.Gallery.Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
<ItemGroup>
<_Globbed_Compile Remove="Converters\DateTimeToDateTimeOffsetConverter.cs" />
<_Globbed_Compile Remove="Converters\FromValueToStringConverter.cs" />
<_Globbed_Compile Remove="Entities\Data\Plant.cs" />
<_Globbed_Compile Remove="Views\SamplePages\DataGridSamplePage.xaml.cs" />
</ItemGroup>
<ItemGroup>
<_Globbled_Page Remove="Views\SamplePages\DataGridSamplePage.xaml" />
</ItemGroup>
</Project>
Loading

0 comments on commit 7efa791

Please sign in to comment.