Skip to content

Commit 31ba034

Browse files
authored
Merge pull request #249 from AlexanderBlackman/experiment
Limited selection checkbox movement to VisibleWhenSelected.
2 parents c42a851 + 8cebdf5 commit 31ba034

4 files changed

Lines changed: 39 additions & 35 deletions

File tree

src/TableView.Properties.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.UI.Xaml;
1+
using Microsoft.UI.Xaml;
22
using Microsoft.UI.Xaml.Controls;
33
using Microsoft.UI.Xaml.Controls.Primitives;
44
using Microsoft.UI.Xaml.Data;

src/TableView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using CommunityToolkit.WinUI;
1+
using CommunityToolkit.WinUI;
22
using Microsoft.UI;
33
using Microsoft.UI.Xaml;
44
using Microsoft.UI.Xaml.Controls;

src/TableViewRow.cs

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Collections.Specialized;
1212
using System.Data;
1313
using System.Linq;
14+
using System.Threading.Tasks;
1415
using Windows.Foundation;
1516
using WinUI.TableView.Helpers;
1617

@@ -506,39 +507,6 @@ internal void EnsureLayout()
506507
selectionIndicator = fontIcon?.Parent as Border;
507508
}
508509

509-
if (selectionIndicator is not null)
510-
{
511-
if (IsSelected)
512-
{
513-
// Assign a TranslateTransform for animation
514-
var translateTransform = new TranslateTransform();
515-
selectionIndicator.RenderTransform = translateTransform;
516-
517-
var toValue = Math.Round(-detailsHeight / 2); // move up or down
518-
519-
var animation = new DoubleAnimation
520-
{
521-
To = toValue,
522-
Duration = new Duration(TimeSpan.Zero)
523-
};
524-
525-
var storyboard = new Storyboard();
526-
Storyboard.SetTarget(animation, translateTransform);
527-
Storyboard.SetTargetProperty(animation, "Y"); // vertical movement
528-
storyboard.Children.Add(animation);
529-
530-
storyboard.Begin();
531-
}
532-
else
533-
{
534-
// Row is not selected → reset any previous offset
535-
if (selectionIndicator.RenderTransform is TranslateTransform tt)
536-
tt.Y = 0;
537-
else
538-
selectionIndicator.RenderTransform = null;
539-
}
540-
}
541-
542510

543511
_selectionBackground ??= _itemPresenter?.FindDescendants()
544512
.OfType<Border>()
@@ -550,6 +518,7 @@ internal void EnsureLayout()
550518
_focusVisualMargin.Right,
551519
_focusVisualMargin.Bottom + GetHorizontalGridlineHeight());
552520

521+
EnsureSelectionIndicatorPosition(detailsHeight, selectionIndicator);
553522
#endif
554523
if (_selectionBackground is not null)
555524
{
@@ -562,6 +531,36 @@ internal void EnsureLayout()
562531
}
563532
}
564533

534+
/// <summary>
535+
/// Ensures the position of the selection indicator.
536+
/// </summary>
537+
private async void EnsureSelectionIndicatorPosition(double detailsHeight, Border? selectionIndicator)
538+
{
539+
await Task.Yield(); // let the animations and visual state changes complete
540+
541+
if (selectionIndicator is not null)
542+
{
543+
// Assign a TranslateTransform for animation
544+
var translateTransform = new TranslateTransform();
545+
selectionIndicator.RenderTransform = translateTransform;
546+
547+
var toValue = RowPresenter?.IsDetailsPanelVisible ?? false ? Math.Round(-detailsHeight / 2) : 0; // move up or down
548+
549+
var animation = new DoubleAnimation
550+
{
551+
To = toValue,
552+
Duration = new Duration(TimeSpan.Zero)
553+
};
554+
555+
var storyboard = new Storyboard();
556+
Storyboard.SetTarget(animation, translateTransform);
557+
Storyboard.SetTargetProperty(animation, "Y"); // vertical movement
558+
storyboard.Children.Add(animation);
559+
560+
storyboard.Begin();
561+
}
562+
}
563+
565564
/// <summary>
566565
/// Ensures alternate colors are applied to the row.
567566
/// </summary>

src/TableViewRowPresenter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,4 +455,9 @@ public void ClearCells()
455455
/// Gets or sets the TableView associated with the presenter.
456456
/// </summary>
457457
public TableView? TableView { get; private set; }
458+
459+
/// <summary>
460+
/// Gets a value indicating whether the row details panel is currently visible.
461+
/// </summary>
462+
internal bool IsDetailsPanelVisible => _detailsPanel?.Visibility is Visibility.Visible;
458463
}

0 commit comments

Comments
 (0)