From 4d12782b5e1856f7630b886c06f186db2a1a0a02 Mon Sep 17 00:00:00 2001 From: Jeremy Alles Date: Tue, 7 Apr 2020 10:12:32 +0200 Subject: [PATCH] add proposal for treeview selection changed event --- active/TreeView/SelectionChangedEvent.md | 120 +++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 active/TreeView/SelectionChangedEvent.md diff --git a/active/TreeView/SelectionChangedEvent.md b/active/TreeView/SelectionChangedEvent.md new file mode 100644 index 000000000..45e482296 --- /dev/null +++ b/active/TreeView/SelectionChangedEvent.md @@ -0,0 +1,120 @@ + + + + +# Background + + + + + + + + + +The `TreeView` control is lacking an event to track when selection has changed. While other list based controls (`ListView`, `ComboBox`, ...) have such API the `TreeView` control does not. + +The original issue in the WinUI repo for this is here: https://github.com/microsoft/microsoft-ui-xaml/issues/322 + +# Description + +This API is adding an event whenever the selected item of a `TreeView` control has changed. + +# Examples + +``` +private void Initialize() +{ + var treeView = new TreeView(); + treeView.SelectionChanged += OnSelectionChanged; +} + +private void OnSelectionChanged(object sender, TreeViewSelectionChangedEventArgs e) +{ + foreach (var addedItem in e.AddedItems) + { + // ... + } + + foreach (var removedItems in e.RemovedItems) + { + // ... + } +} +``` + + + + + + + +# Remarks + + + +The API is available as preview already in WinUI and was merged in this PR: https://github.com/microsoft/microsoft-ui-xaml/pull/2063 + +# API Notes + +N/A + + + + +# API Details + +``` +runtimeclass TreeViewSelectionChangedEventArgs +{ + Windows.Foundation.Collections.IVector AddedItems{ get; }; + Windows.Foundation.Collections.IVector RemovedItems{ get; }; +} + +runtimeclass TreeView : Windows.UI.Xaml.Controls.Control { + event Windows.Foundation.TypedEventHandler SelectionChanged; +} +``` + +# Appendix + +The underlying implementation of this event is using two different approaches depending on multiselection status. + +When multiselection **is not** enabled on the treeview control, the implementation is just using the `SelectionChanged` event of the `ListView` control used internally. + +When multiselection **is** enabled on the treeview control, selection changed is tracked differently. + +While there are two code paths, this does not imply any user facing difference in how the API can be consumed. \ No newline at end of file