diff --git a/dev/TreeView/InteractionTests/TreeViewTests.cs b/dev/TreeView/InteractionTests/TreeViewTests.cs index af54f97f03..36c5bc1a1d 100644 --- a/dev/TreeView/InteractionTests/TreeViewTests.cs +++ b/dev/TreeView/InteractionTests/TreeViewTests.cs @@ -1807,6 +1807,41 @@ private void TreeViewItemUIATest(bool isContentMode = false) } } + [TestMethod] + [TestProperty("TreeViewTestSuite", "B")] + public void TreeViewListMultipleSelectionUIATest() + { + using (var setup = new TestSetupHelper("TreeView Tests")) + { + SetContentMode(false); + + UIObject ItemRoot = LabelFirstItem(); + + InputHelper.Tap(ItemRoot); + + ClickButton("LabelItems"); + ClickButton("ToggleSelectionMode"); + + Log.Comment("Retrieve first item as generic UIElement"); + UIObject Item1 = FindElement.ById("Root.1"); + Verify.IsNotNull(Item1, "Verifying that we found a UIElement called Root.1"); + + Item1.SetFocus(); + AutomationElement itemPeer = AutomationElement.FocusedElement; + + var selectionItemPeer = (SelectionItemPattern)itemPeer.GetCurrentPattern(SelectionItemPattern.Pattern); + var treeViewListPeer = selectionItemPeer.Current.SelectionContainer; + + var multipleSelectionPattern = (SelectionPattern)treeViewListPeer.GetCurrentPattern(SelectionPattern.Pattern); + Verify.IsNotNull(multipleSelectionPattern); + Verify.IsTrue(multipleSelectionPattern.Current.CanSelectMultiple); + Verify.IsFalse(multipleSelectionPattern.Current.IsSelectionRequired); + var elements = multipleSelectionPattern.Current.GetSelection(); + Verify.IsNotNull(elements); + Verify.AreEqual(0, elements.Length); + } + } + [TestMethod] [TestProperty("TreeViewTestSuite", "B")] [TestProperty("Platform", "Desktop")] diff --git a/dev/TreeView/TreeViewItem.xaml b/dev/TreeView/TreeViewItem.xaml index 8de244c834..9a25161cca 100644 --- a/dev/TreeView/TreeViewItem.xaml +++ b/dev/TreeView/TreeViewItem.xaml @@ -341,7 +341,13 @@ - + - - - + + + - + - + Background="{ThemeResource SystemControlBackgroundAccentBrush}" + BorderThickness="2" + BorderBrush="{ThemeResource SystemControlBackgroundChromeWhiteBrush}"> + - - + + TreeViewListAutomationPeer::DropEffects() winrt::IInspectable TreeViewListAutomationPeer::GetPatternCore(winrt::PatternInterface const& patternInterface) { - if (patternInterface == winrt::PatternInterface::DropTarget) + if (patternInterface == winrt::PatternInterface::DropTarget || + (patternInterface == winrt::PatternInterface::Selection && IsMultiselect())) { return *this; } @@ -44,4 +45,26 @@ winrt::IInspectable TreeViewListAutomationPeer::GetPatternCore(winrt::PatternInt winrt::AutomationControlType TreeViewListAutomationPeer::GetAutomationControlTypeCore() { return winrt::AutomationControlType::Tree; -} \ No newline at end of file +} + +// ISelectionProvider +bool TreeViewListAutomationPeer::CanSelectMultiple() +{ + return IsMultiselect()? true: __super::CanSelectMultiple(); +} + +bool TreeViewListAutomationPeer::IsSelectionRequried() +{ + return IsMultiselect()? false : __super::CanSelectMultiple(); +} + +winrt::com_array TreeViewListAutomationPeer::GetSelection() +{ + // The selected items might be collapsed, virtualized, so getting an accurate list of selected items is not possible. + return {}; +} + +bool TreeViewListAutomationPeer::IsMultiselect() +{ + return winrt::get_self(Owner().as())->IsMultiselect(); +} diff --git a/dev/TreeView/TreeViewListAutomationPeer.h b/dev/TreeView/TreeViewListAutomationPeer.h index 871d653599..310f395591 100644 --- a/dev/TreeView/TreeViewListAutomationPeer.h +++ b/dev/TreeView/TreeViewListAutomationPeer.h @@ -9,7 +9,8 @@ class TreeViewListAutomationPeer : public ReferenceTracker< TreeViewListAutomationPeer, winrt::implementation::TreeViewListAutomationPeerT, - winrt::IDropTargetProvider> + winrt::IDropTargetProvider, + winrt::ISelectionProvider> { public: TreeViewListAutomationPeer(winrt::TreeViewList const& owner); @@ -21,7 +22,15 @@ class TreeViewListAutomationPeer : // IItemsControlAutomationPeerOverrides2 winrt::ItemAutomationPeer OnCreateItemAutomationPeer(winrt::IInspectable const& item); - //DropTargetProvider methods + // IDropTargetProvider winrt::hstring DropEffect(); winrt::com_array DropEffects(); + + // ISelectionProvider + bool CanSelectMultiple(); + bool IsSelectionRequried(); + winrt::com_array GetSelection(); + +private: + bool IsMultiselect(); };