Skip to content

Commit

Permalink
feat(listview): add support for ListView.IsMultiSelectCheckBoxEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
ramezgerges committed Sep 27, 2023
1 parent 7d0c72e commit 2e02592
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,154 @@ public async Task NoItemSelectedSingle()
Assert.AreEqual(list.SelectedIndex, -1);
}

[TestMethod]
[RunsOnUIThread]
public async Task When_SingleSelection_IsMultiSelectCheckBoxEnabled()
{
var singleList = new ListView
{
SelectionMode = ListViewSelectionMode.Single,
Items =
{
new ListViewItem
{
Content = "child 1"
}
}
};

var multipleList = new ListView
{
SelectionMode = ListViewSelectionMode.Multiple,
Items =
{
new ListViewItem
{
Content = "child 1"
}
}
};

var extendedList = new ListView
{
SelectionMode = ListViewSelectionMode.Extended,
Items =
{
new ListViewItem
{
Content = "child 1"
}
}
};

var singleList2 = new ListView
{
SelectionMode = ListViewSelectionMode.Single,
IsMultiSelectCheckBoxEnabled = true,
Items =
{
new ListViewItem
{
Content = "child 1"
}
}
};

var multipleList2 = new ListView
{
SelectionMode = ListViewSelectionMode.Multiple,
IsMultiSelectCheckBoxEnabled = true,
Items =
{
new ListViewItem
{
Content = "child 1"
}
}
};

var extendedList2 = new ListView
{
SelectionMode = ListViewSelectionMode.Extended,
IsMultiSelectCheckBoxEnabled = true,
Items =
{
new ListViewItem
{
Content = "child 1"
}
}
};

var singleList3 = new ListView
{
SelectionMode = ListViewSelectionMode.Single,
IsMultiSelectCheckBoxEnabled = false,
Items =
{
new ListViewItem
{
Content = "child 1"
}
}
};

var multipleList3 = new ListView
{
SelectionMode = ListViewSelectionMode.Multiple,
IsMultiSelectCheckBoxEnabled = false,
Items =
{
new ListViewItem
{
Content = "child 1"
}
}
};

var extendedList3 = new ListView
{
SelectionMode = ListViewSelectionMode.Extended,
IsMultiSelectCheckBoxEnabled = false,
Items =
{
new ListViewItem
{
Content = "child 1"
}
}
};

var sp = new StackPanel
{
Children =
{
singleList,
multipleList,
extendedList,
singleList2,
multipleList2,
extendedList2,
singleList3,
multipleList3,
extendedList3
}
};

WindowHelper.WindowContent = sp;
await WindowHelper.WaitForIdle();

Assert.AreEqual(Visibility.Collapsed, ((Border)singleList.FindName("MultiSelectSquare")).Visibility);
Assert.AreEqual(Visibility.Visible, ((Border)multipleList.FindName("MultiSelectSquare")).Visibility);
Assert.AreEqual(Visibility.Collapsed, ((Border)extendedList.FindName("MultiSelectSquare")).Visibility);
Assert.AreEqual(Visibility.Collapsed, ((Border)singleList2.FindName("MultiSelectSquare")).Visibility);
Assert.AreEqual(Visibility.Visible, ((Border)multipleList2.FindName("MultiSelectSquare")).Visibility);
Assert.AreEqual(Visibility.Collapsed, ((Border)extendedList2.FindName("MultiSelectSquare")).Visibility);
Assert.AreEqual(Visibility.Collapsed, ((Border)singleList3.FindName("MultiSelectSquare")).Visibility);
Assert.AreEqual(Visibility.Collapsed, ((Border)multipleList3.FindName("MultiSelectSquare")).Visibility);
Assert.AreEqual(Visibility.Collapsed, ((Border)extendedList3.FindName("MultiSelectSquare")).Visibility);
}

#if HAS_UNO
[TestMethod]
[RunsOnUIThread]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,6 @@ public bool ShowsScrollingPlaceholders
}
}
#endif
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public bool IsMultiSelectCheckBoxEnabled
{
get
{
return (bool)this.GetValue(IsMultiSelectCheckBoxEnabledProperty);
}
set
{
this.SetValue(IsMultiSelectCheckBoxEnabledProperty, value);
}
}
#endif
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::System.Collections.Generic.IReadOnlyList<global::Windows.UI.Xaml.Data.ItemIndexRange> SelectedRanges
Expand Down Expand Up @@ -231,14 +217,6 @@ public bool IsActiveView
nameof(ReorderMode), typeof(global::Windows.UI.Xaml.Controls.ListViewReorderMode),
typeof(global::Windows.UI.Xaml.Controls.ListViewBase),
new Windows.UI.Xaml.FrameworkPropertyMetadata(default(global::Windows.UI.Xaml.Controls.ListViewReorderMode)));
#endif
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static global::Windows.UI.Xaml.DependencyProperty IsMultiSelectCheckBoxEnabledProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
nameof(IsMultiSelectCheckBoxEnabled), typeof(bool),
typeof(global::Windows.UI.Xaml.Controls.ListViewBase),
new Windows.UI.Xaml.FrameworkPropertyMetadata(default(bool)));
#endif
// Skipping already declared property SingleSelectionFollowsFocusProperty
// Skipping already declared method Windows.UI.Xaml.Controls.ListViewBase.ListViewBase()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Windows.UI.Xaml;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls.Primitives;
using NotImplementedException = System.NotImplementedException;

namespace Windows.UI.Xaml.Controls;

Expand All @@ -22,4 +25,24 @@ public bool SingleSelectionFollowsFocus
typeof(bool),
typeof(ListViewBase),
new FrameworkPropertyMetadata(true));

public bool IsMultiSelectCheckBoxEnabled
{
get => (bool)GetValue(IsMultiSelectCheckBoxEnabledProperty);
set => SetValue(IsMultiSelectCheckBoxEnabledProperty, value);
}

public static DependencyProperty IsMultiSelectCheckBoxEnabledProperty { get; } =
DependencyProperty.Register(
nameof(IsMultiSelectCheckBoxEnabled), typeof(bool),
typeof(ListViewBase),
new FrameworkPropertyMetadata(true, (o, args) => ((ListViewBase)o).OnIsMultiSelectCheckBoxEnabledPropertyChanged(args)));

private void OnIsMultiSelectCheckBoxEnabledPropertyChanged(DependencyPropertyChangedEventArgs args)
{
foreach (var item in GetItemsPanelChildren().OfType<SelectorItem>())
{
ApplyMultiSelectState(item);
}
}
}
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Controls/ListViewBase/ListViewBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ internal override void ContainerClearedForItem(object item, SelectorItem itemCon
/// <param name="selectorItem"></param>
internal void ApplyMultiSelectState(SelectorItem selectorItem)
{
selectorItem.ApplyMultiSelectState(IsSelectionMultiple);
selectorItem.ApplyMultiSelectState(SelectionMode == ListViewSelectionMode.Multiple);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Uno.UI/UI/Xaml/Controls/Primitives/SelectorItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private protected override void OnIsEnabledChanged(IsEnabledChangedEventArgs e)
/// </summary>
internal void ApplyMultiSelectState(bool isSelectionMultiple)
{
if (isSelectionMultiple)
if (isSelectionMultiple && Selector is not ListViewBase { IsMultiSelectCheckBoxEnabled: false })
{
// We can safely always go to multiselect state
VisualStateManager.GoToState(this, "MultiSelectEnabled", useTransitions: true);
Expand Down Expand Up @@ -285,7 +285,7 @@ private protected override void OnLoaded()
UpdateCommonStates();
if (Selector is ListView lv)
{
ApplyMultiSelectState(lv.IsSelectionMultiple);
ApplyMultiSelectState(lv.SelectionMode == ListViewSelectionMode.Multiple);
}

// TODO: This may need to be adjusted later when we remove the Visual State mixins.
Expand Down

0 comments on commit 2e02592

Please sign in to comment.