Skip to content
Merged
9 changes: 8 additions & 1 deletion samples/WinUI.TableView.SampleApp/Pages/SelectionPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
OnContent="True"
OffContent="False"
IsOn="{Binding IsReadOnly, Mode=TwoWay, ElementName=tableView}" />
<ToggleSwitch Header="ShowDragRectangle"
OnContent="True"
OffContent="False"
IsOn="{Binding ShowDragRectangle, Mode=TwoWay, ElementName=tableView}" />
<InfoBar IsOpen="True"
IsClosable="False"
Title="Selected Item">
Expand Down Expand Up @@ -79,7 +83,8 @@
ItemsSource="{Binding Items}"
SelectionMode="$(SelectionMode)"
SelectionUnit="$(SelectionUnit)"
IsReadOnly="$(IsReadOnly)" /&gt;
IsReadOnly="$(IsReadOnly)"
ShowDragRectangle="$(ShowDragRectangle)" /&gt;
</x:String>
</controls:SamplePresenter.Xaml>
<controls:SamplePresenter.Substitutions>
Expand All @@ -89,6 +94,8 @@
Value="{x:Bind tableView.SelectionUnit, Mode=OneWay}" />
<controls:CodeSubstitution Key="IsReadOnly"
Value="{x:Bind tableView.IsReadOnly, Mode=OneWay}" />
<controls:CodeSubstitution Key="ShowDragRectangle"
Value="{x:Bind tableView.ShowDragRectangle, Mode=OneWay}" />
</controls:SamplePresenter.Substitutions>
</controls:SamplePresenter>
</Grid>
Expand Down
41 changes: 41 additions & 0 deletions src/TableView.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ public bool CanPaste
set => SetValue(CanPasteProperty, value);
}

/// <summary>
/// Identifies the <see cref="ShowDragRectangle"/> dependency property.
/// </summary>
public static readonly DependencyProperty ShowDragRectangleProperty = DependencyProperty.Register(nameof(ShowDragRectangle), typeof(bool), typeof(TableView), new PropertyMetadata(true, OnShowDragRectangleChanged));

/// <summary>
/// Gets or sets a value indicating whether opening the column filter over header right-click is enabled.
/// </summary>
Expand Down Expand Up @@ -365,6 +370,15 @@ public bool ShowFilterItemsCount
set => SetValue(ShowFilterItemsCountProperty, value);
}

/// <summary>
/// Gets or sets a value indicating whether the drag selection rectangle is shown during cell drag selection.
/// </summary>
public bool ShowDragRectangle
{
get => (bool)GetValue(ShowDragRectangleProperty);
set => SetValue(ShowDragRectangleProperty, value);
}

/// <summary>
/// Gets or sets a value that indicates whether the TableView should force select the Row or Cell depending on the SelectionUnit
/// </summary>
Expand Down Expand Up @@ -404,6 +418,16 @@ public bool ForceRowOrCellSelectionOnContextRequested
/// </summary>
internal bool IsEditing { get; private set; }

/// <summary>
/// Gets the canvas that hosts the drag selection rectangle.
/// </summary>
internal Canvas? DragRectangleCanvas { get; private set; }

/// <summary>
/// Gets a value indicating whether a drag selection is currently in progress.
/// </summary>
internal bool IsDragSelecting { get; private set; }

/// <summary>
/// Gets the visibility states of details pane for each item.
/// </summary>
Expand Down Expand Up @@ -928,6 +952,23 @@ private static void OnIsReadOnlyChanged(DependencyObject d, DependencyPropertyCh
}
}

/// <summary>
/// Handles changes to the ShowDragRectangle property.
/// </summary>
private static void OnShowDragRectangleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is TableView tableView && e.NewValue is false)
{
// Hide the rectangle visual but don't stop drag selection or auto-scroll
if (tableView._dragRectangle is not null)
{
tableView._dragRectangle.Visibility = Visibility.Collapsed;
}

tableView._dragStartPoint = null;
}
}

/// <summary>
/// Handles changes to the CanFilterColumns property.
/// </summary>
Expand Down
Loading
Loading