Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unblock DataTable on Uno #496

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions components/DataTable/src/DataTable/DataColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.Versioning;

namespace CommunityToolkit.WinUI.Controls;

[SupportedOSPlatform("osx10.14")]
[SupportedOSPlatform("maccatalyst13.1")]
[TemplatePart(Name = nameof(PART_ColumnSizer), Type = typeof(ContentSizer))]
public partial class DataColumn : ContentControl
{
Expand Down Expand Up @@ -97,18 +101,18 @@ protected override void OnApplyTemplate()

private void PART_ColumnSizer_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
ColumnResizedByUserSizer();
ColumnResizedByUserSizer(true);
}

private void PART_ColumnSizer_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
ColumnResizedByUserSizer();
ColumnResizedByUserSizer(false);
}

private void ColumnResizedByUserSizer()
private void ColumnResizedByUserSizer(bool resizing)
{
// Update our internal representation to be our size now as a fixed value.
CurrentWidth = new(this.ActualWidth);
CurrentWidth = new(this.Width);

// Notify the rest of the table to update
if (_parent?.TryGetTarget(out DataTable? parent) == true
Expand Down
1 change: 1 addition & 0 deletions components/DataTable/src/DataTable/DataColumn.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ContentPresenter Margin="{TemplateBinding Padding}"
Content="{TemplateBinding Content}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Foreground="{TemplateBinding Foreground}" />
Expand Down
18 changes: 16 additions & 2 deletions components/DataTable/src/DataTable/DataRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.Versioning;
using TreeView = Microsoft.UI.Xaml.Controls.TreeView;

namespace CommunityToolkit.WinUI.Controls;

[SupportedOSPlatform("osx10.14")]
[SupportedOSPlatform("maccatalyst13.1")]
public partial class DataRow : Panel
{
// TODO: Create our own helper class here for the Header as well vs. straight-Grid.
// TODO: WeakReference?
private Panel? _parentPanel;
#pragma warning disable CA2213
private DataTable? _parentTable;
#pragma warning restore CA2213

private bool _isTreeView;
private double _treePadding;
Expand Down Expand Up @@ -42,21 +47,30 @@ private void DataRow_Unloaded(object sender, RoutedEventArgs e)
// 1a. Get parent ItemsPresenter to find header
if (this.FindAscendant<ItemsPresenter>() is ItemsPresenter itemsPresenter)
{
#if !HAS_UNO
// 2. Quickly check if the header is just what we're looking for.
if (itemsPresenter.Header is Grid or DataTable)
{
panel = itemsPresenter.Header as Panel;
}
else
{
// 3. Otherwise, try and find the inner thing we want.
panel = itemsPresenter.FindDescendant<Panel>(static (element) => element is Grid or DataTable);
#endif
// 3. Use a container from outside
panel = this.FindAscendant<DataTableContainer>()?.Header;

// 4. Otherwise, try and find the inner thing we want.
panel ??= itemsPresenter.FindDescendant<Panel>(static (element) => element is Grid or DataTable);
#if !HAS_UNO
}
#endif

// Check if we're in a TreeView
_isTreeView = itemsPresenter.FindAscendant<TreeView>() is TreeView;
}

panel ??= this.FindAscendant<DataTableContainer>()?.Header;

// 1b. If we can't find the ItemsPresenter, then we reach up outside to find the next thing we could use as a parent
panel ??= this.FindAscendant<Panel>(static (element) => element is Grid or DataTable);

Expand Down
6 changes: 6 additions & 0 deletions components/DataTable/src/DataTable/DataTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
// See the LICENSE file in the project root for more information.

using System.Runtime.CompilerServices;
using System.Runtime.Versioning;

namespace CommunityToolkit.WinUI.Controls;

/// <summary>
/// A <see cref="DataTable"/> is a <see cref="Panel"/> which lays out <see cref="DataColumn"/>s based on
/// their configured properties (akin to <see cref="ColumnDefinition"/>); similar to a <see cref="Grid"/> with a single row.
/// </summary>
///
[SupportedOSPlatform("osx10.14")]
[SupportedOSPlatform("maccatalyst13.1")]
public partial class DataTable : Panel
{
// TODO: We should cache this result and update if column properties change
Expand All @@ -20,12 +24,14 @@ public partial class DataTable : Panel

internal void ColumnResized()
{
#pragma warning disable Uno0001
InvalidateArrange();

foreach (var row in Rows)
{
row.InvalidateArrange();
}
#pragma warning restore Uno0001
}

//// TODO: Would we want this named 'Spacing' instead if we support an Orientation in the future for columns being items instead of rows?
Expand Down
34 changes: 34 additions & 0 deletions components/DataTable/src/DataTable/DataTableContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.Versioning;

namespace CommunityToolkit.WinUI.Controls;

[SupportedOSPlatform("osx10.14")]
[SupportedOSPlatform("maccatalyst13.1")]
public partial class DataTableContainer : Grid
{
#pragma warning disable CA2213
private Panel? _header;
#pragma warning restore CA2213
public Panel? Header
{
get
{
if (_header != null)
{
return _header;
}

if (this.FindDescendant<Panel>(static (element) => element is Grid or DataTable) is Panel panel)
{
_header = panel;
return _header;
}

return null;
}
}
}
2 changes: 1 addition & 1 deletion components/DataTable/src/MultiTarget.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
MultiTarget is a custom property that indicates which target a project is designed to be built for / run on.
Used to create project references, generate solution files, enable/disable TargetFrameworks, and build nuget packages.
-->
<MultiTarget>uwp;wasdk;</MultiTarget>
<MultiTarget>uwp;wasdk;wasm;linuxgtk;macos;maccatalyst;</MultiTarget>
</PropertyGroup>
</Project>