Skip to content

Commit 7efa791

Browse files
Merge pull request #1003 from unoplatform/dev/doti/WCT-DataGrid
feat: Add WCT `DataGrid` sample
2 parents 88e2829 + ac1ce55 commit 7efa791

File tree

13 files changed

+685
-0
lines changed

13 files changed

+685
-0
lines changed

Uno.Gallery/Uno.Gallery.Mobile/Uno.Gallery.Mobile.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
<ItemGroup>
3030
<PackageReference Include="Uno.CommunityToolkit.WinUI.UI.Controls" Version="7.1.200-dev.13.gef3f523648" />
31+
<PackageReference Include="Uno.CommunityToolkit.WinUI.UI.Controls.DataGrid" Version="7.1.200-dev.13.gef3f523648" />
3132
<PackageReference Include="Uno.Cupertino.WinUI" Version="4.0.0-dev.126" />
3233
<PackageReference Include="Uno.Extensions.Logging.OSLog" Version="1.6.0-dev.2" />
3334
<PackageReference Include="Uno.Fonts.Fluent" Version="2.3.0" />
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Microsoft.UI.Xaml.Data;
2+
using System;
3+
4+
namespace Uno.Gallery.Converters;
5+
6+
public class DateTimeToDateTimeOffsetConverter : IValueConverter
7+
{
8+
public object Convert(object value, Type targetType, object parameter, string language)
9+
{
10+
DateTime date = (DateTime)value;
11+
return new DateTimeOffset(date);
12+
}
13+
14+
public object ConvertBack(object value, Type targetType, object parameter, string language)
15+
{
16+
DateTimeOffset dateTimeOffset = (DateTimeOffset)value;
17+
return dateTimeOffset.DateTime;
18+
}
19+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Microsoft.UI;
2+
using Microsoft.UI.Xaml.Data;
3+
using System;
4+
using System.Linq;
5+
using System.Reflection;
6+
using Windows.UI;
7+
8+
namespace Uno.Gallery.Converters;
9+
10+
public class FromValueToStringConverter : IValueConverter
11+
{
12+
public object Convert(object value, Type targetType, object parameter, string language)
13+
{
14+
if (value is Color color)
15+
{
16+
// Use reflection to get the name of the color
17+
PropertyInfo colorProperty = typeof(Colors).GetRuntimeProperties().FirstOrDefault(p => ((Color)p.GetValue(null)).Equals(color));
18+
if (colorProperty != null)
19+
{
20+
return colorProperty.Name;
21+
}
22+
}
23+
24+
return null;
25+
}
26+
27+
public object ConvertBack(object value, Type targetType, object parameter, string language) => throw new NotSupportedException("Only one-way conversion is supported.");
28+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using static Uno.Gallery.Entities.Data.Plant;
5+
6+
namespace Uno.Gallery.Entities.Data;
7+
8+
public class Plant : IComparable
9+
{
10+
public Plant(
11+
string plantName,
12+
int plantsCount,
13+
FruitOrVegetableEnum fruitOrVegetable,
14+
DateTime plantDate,
15+
bool isWatered)
16+
{
17+
PlantName = plantName;
18+
PlantsCount = plantsCount;
19+
FruitOrVegetable = fruitOrVegetable;
20+
PlantDate = plantDate;
21+
IsWatered = isWatered;
22+
}
23+
24+
public string PlantName { get; set; }
25+
public int PlantsCount { get; set; }
26+
public enum FruitOrVegetableEnum { Fruit, Vegetable }
27+
public FruitOrVegetableEnum FruitOrVegetable { get; set; }
28+
public DateTime PlantDate { get; set; }
29+
public bool IsWatered { get; set; }
30+
31+
public IEnumerable<FruitOrVegetableEnum> FruitOrVegetableEnumValues { get; } =
32+
Enum.GetValues(typeof(FruitOrVegetableEnum)).Cast<FruitOrVegetableEnum>();
33+
34+
public int CompareTo(object obj)
35+
{
36+
if (obj == null)
37+
return 1;
38+
39+
if (obj is Plant otherPlant)
40+
{
41+
return PlantName.CompareTo(otherPlant.PlantName);
42+
}
43+
else
44+
{
45+
throw new ArgumentException("Object is not a Plant");
46+
}
47+
}
48+
}
49+
50+
public class PlantCollection : List<Plant>
51+
{
52+
public PlantCollection() : base(GetPlants()) { }
53+
54+
private static IEnumerable<Plant> GetPlants()
55+
{
56+
yield return new Plant("Tomato", 12, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 5, 29), true);
57+
yield return new Plant("Cucumber", 10, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 6, 15), true);
58+
yield return new Plant("Bell Pepper", 15, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 4, 15), false);
59+
yield return new Plant("Lettuce", 8, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 4, 1), true);
60+
yield return new Plant("Strawberry", 35, FruitOrVegetableEnum.Fruit, new DateTime(2021, 5, 1), true);
61+
yield return new Plant("Carrot", 5, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 3, 15), false);
62+
yield return new Plant("Watermelon", 1, FruitOrVegetableEnum.Fruit, new DateTime(2021, 6, 1), true);
63+
yield return new Plant("Blueberries", 31, FruitOrVegetableEnum.Fruit, new DateTime(2021, 6, 20), true);
64+
yield return new Plant("Eggplant", 7, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 5, 10), false);
65+
yield return new Plant("Broccoli", 9, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 4, 20), false);
66+
yield return new Plant("Raspberry", 18, FruitOrVegetableEnum.Fruit, new DateTime(2021, 5, 25), false);
67+
yield return new Plant("Pumpkin", 3, FruitOrVegetableEnum.Fruit, new DateTime(2021, 6, 10), true);
68+
yield return new Plant("Green Beans", 50, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 5, 5), true);
69+
yield return new Plant("Kale", 10, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 4, 15), true);
70+
yield return new Plant("Grapes", 25, FruitOrVegetableEnum.Fruit, new DateTime(2021, 9, 1), true);
71+
yield return new Plant("Potato", 6, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 10, 15), false);
72+
yield return new Plant("Orange", 20, FruitOrVegetableEnum.Fruit, new DateTime(2021, 11, 1), true);
73+
yield return new Plant("Zucchini", 11, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 8, 20), false);
74+
yield return new Plant("Apple", 30, FruitOrVegetableEnum.Fruit, new DateTime(2021, 10, 1), true);
75+
yield return new Plant("Spinach", 5, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 7, 15), true);
76+
yield return new Plant("Pear", 15, FruitOrVegetableEnum.Fruit, new DateTime(2021, 8, 1), true);
77+
yield return new Plant("Celery", 7, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 9, 10), true);
78+
yield return new Plant("Pineapple", 2, FruitOrVegetableEnum.Fruit, new DateTime(2021, 12, 1), true);
79+
yield return new Plant("Cherry", 40, FruitOrVegetableEnum.Fruit, new DateTime(2021, 6, 1), true);
80+
yield return new Plant("Mango", 8, FruitOrVegetableEnum.Fruit, new DateTime(2021, 9, 15), true);
81+
yield return new Plant("Cabbage", 12, FruitOrVegetableEnum.Vegetable, new DateTime(2021, 11, 15), true);
82+
}
83+
}

Uno.Gallery/Uno.Gallery.Shared/Entities/SampleCategory.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@ public enum SampleCategory
2323

2424
[SampleCategoryInfo("\uF0B4", "Toolkit")]
2525
Toolkit,
26+
27+
[SampleCategoryInfo("\uE821", "Community Toolkit")]
28+
CommunityToolkit,
2629
}
2730
}

Uno.Gallery/Uno.Gallery.Shared/Uno.Gallery.Shared.projitems

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
<Compile Include="$(MSBuildThisFileDirectory)Controls\ContentPageLayout.cs" />
143143
<Compile Include="$(MSBuildThisFileDirectory)Controls\OverviewSampleView.cs" />
144144
<Compile Include="$(MSBuildThisFileDirectory)Controls\SamplePageLayout.Properties.cs" />
145+
<Compile Include="$(MSBuildThisFileDirectory)Converters\DateTimeToDateTimeOffsetConverter.cs" />
145146
<Compile Include="$(MSBuildThisFileDirectory)Converters\DebugConverter.cs" />
146147
<Compile Include="$(MSBuildThisFileDirectory)Converters\EnumDescriptionConverter.cs" />
147148
<Compile Include="$(MSBuildThisFileDirectory)Converters\EnumDesignConverter.cs" />
@@ -154,11 +155,13 @@
154155
<Compile Include="$(MSBuildThisFileDirectory)Controls\FluentColorAccentView.cs" />
155156
<Compile Include="$(MSBuildThisFileDirectory)Controls\ThreeColorPaletteView.cs" />
156157
<Compile Include="$(MSBuildThisFileDirectory)Converters\FromColorBrushToHexConverter.cs" />
158+
<Compile Include="$(MSBuildThisFileDirectory)Converters\FromValueToStringConverter.cs" />
157159
<Compile Include="$(MSBuildThisFileDirectory)Converters\HexToColorConverter.cs" />
158160
<Compile Include="$(MSBuildThisFileDirectory)Converters\RandomColorConverter.cs" />
159161
<Compile Include="$(MSBuildThisFileDirectory)Converters\SecretConverter.cs" />
160162
<Compile Include="$(MSBuildThisFileDirectory)Deeplinking\BranchService.cs" />
161163
<Compile Include="$(MSBuildThisFileDirectory)Domain\AnalyticsService.cs" />
164+
<Compile Include="$(MSBuildThisFileDirectory)Entities\Data\Plant.cs" />
162165
<Compile Include="$(MSBuildThisFileDirectory)Entities\Data\TreeItem.cs" />
163166
<Compile Include="$(MSBuildThisFileDirectory)Entities\Data\Folder.cs" />
164167
<Compile Include="$(MSBuildThisFileDirectory)Entities\SampleCategoryInfoAttribute.cs" />
@@ -182,12 +185,17 @@
182185
<Compile Include="$(MSBuildThisFileDirectory)Selectors\NeumorphicTemplateSelector.cs" />
183186
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Command.cs" />
184187
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\ViewModelBase.cs" />
188+
<Compile Include="$(MSBuildThisFileDirectory)Views\SamplePages\DataGridSamplePage.xaml.cs" />
185189
</ItemGroup>
186190
<ItemGroup>
187191
<ApplicationDefinition Include="$(MSBuildThisFileDirectory)App.xaml">
188192
<SubType>Designer</SubType>
189193
<Generator>MSBuild:Compile</Generator>
190194
</ApplicationDefinition>
195+
<Page Include="$(MSBuildThisFileDirectory)Views\SamplePages\DataGridSamplePage.xaml">
196+
<SubType>Designer</SubType>
197+
<Generator>MSBuild:Compile</Generator>
198+
</Page>
191199
<_Globbled_Page Include="$(MSBuildThisFileDirectory)**/*.xaml" Exclude="@(Page);@(ApplicationDefinition)">
192200
<SubType>Designer</SubType>
193201
<Generator>MSBuild:Compile</Generator>

Uno.Gallery/Uno.Gallery.Shared/Uno.Gallery.Shared.shproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,13 @@
1010
<PropertyGroup />
1111
<Import Project="Uno.Gallery.Shared.projitems" Label="Shared" />
1212
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
13+
<ItemGroup>
14+
<_Globbed_Compile Remove="Converters\DateTimeToDateTimeOffsetConverter.cs" />
15+
<_Globbed_Compile Remove="Converters\FromValueToStringConverter.cs" />
16+
<_Globbed_Compile Remove="Entities\Data\Plant.cs" />
17+
<_Globbed_Compile Remove="Views\SamplePages\DataGridSamplePage.xaml.cs" />
18+
</ItemGroup>
19+
<ItemGroup>
20+
<_Globbled_Page Remove="Views\SamplePages\DataGridSamplePage.xaml" />
21+
</ItemGroup>
1322
</Project>

0 commit comments

Comments
 (0)