-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add proposal for TreeView SelectionChanged event #80
Open
japf
wants to merge
1
commit into
microsoft:master
Choose a base branch
from
japf:user/jealles/treeview-selectionchanged
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<!-- The purpose of this spec is to describe a new feature and | ||
its APIs that make up a new feature in WinUI. --> | ||
|
||
<!-- There are two audiences for the spec. The first are people | ||
that want to evaluate and give feedback on the API, as part of | ||
the submission process. When it's complete | ||
it will be incorporated into the public documentation at | ||
docs.microsoft.com (http://docs.microsoft.com/uwp/toolkits/winui/). | ||
Hopefully we'll be able to copy it mostly verbatim. | ||
So the second audience is everyone that reads there to learn how | ||
and why to use this API. --> | ||
|
||
# Background | ||
<!-- Use this section to provide background context for the new API(s) | ||
in this spec. --> | ||
|
||
<!-- This section and the appendix are the only sections that likely | ||
do not get copied to docs.microsoft.com; they're just an aid to reading this spec. --> | ||
|
||
<!-- If you're modifying an existing API, included a link here to the | ||
existing page(s) --> | ||
|
||
<!-- For example, this section is a place to explain why you're adding this API rather than | ||
modifying an existing API. --> | ||
|
||
<!-- For example, this is a place to provide a brief explanation of some dependent | ||
area, just explanation enough to understand this new API, rather than telling | ||
the reader "go read 100 pages of background information posted at ...". --> | ||
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 | ||
<!-- Use this section to provide a brief description of the feature. | ||
For an example, see the introduction to the PasswordBox control | ||
(http://docs.microsoft.com/windows/uwp/design/controls-and-patterns/password-box). --> | ||
This API is adding an event whenever the selected item of a `TreeView` control has changed. | ||
|
||
# Examples | ||
<!-- Use this section to explain the features of the API, showing | ||
example code with each description. The general format is: | ||
feature explanation, | ||
example code | ||
feature explanation, | ||
example code | ||
etc.--> | ||
``` | ||
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) | ||
{ | ||
// ... | ||
} | ||
} | ||
``` | ||
|
||
|
||
<!-- Code samples should be in C# and/or C++/WinRT --> | ||
|
||
<!-- As an example of this section, see the Examples section for the PasswordBox control | ||
(https://docs.microsoft.com/windows/uwp/design/controls-and-patterns/password-box#examples). --> | ||
|
||
|
||
# Remarks | ||
<!-- Explanation and guidance that doesn't fit into the Examples section. --> | ||
|
||
<!-- APIs should only throw exceptions in exceptional conditions; basically, | ||
only when there's a bug in the caller, such as argument exception. But if for some | ||
reason it's necessary for a caller to catch an exception from an API, call that | ||
out with an explanation either here or in the Examples --> | ||
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 | ||
<!-- Option 1: Give a one or two line description of each API (type | ||
and member), or at least the ones that aren't obvious | ||
from their name. These descriptions are what show up | ||
in IntelliSense. For properties, specify the default value of the property if it | ||
isn't the type's default (for example an int-typed property that doesn't default to zero.) --> | ||
|
||
<!-- Option 2: Put these descriptions in the below API Details section, | ||
with a "///" comment above the member or type. --> | ||
|
||
# API Details | ||
<!-- The exact API, in MIDL3 format (https://docs.microsoft.com/en-us/uwp/midl-3/) --> | ||
``` | ||
runtimeclass TreeViewSelectionChangedEventArgs | ||
{ | ||
Windows.Foundation.Collections.IVector<Object> AddedItems{ get; }; | ||
Windows.Foundation.Collections.IVector<Object> RemovedItems{ get; }; | ||
} | ||
|
||
runtimeclass TreeView : Windows.UI.Xaml.Controls.Control { | ||
event Windows.Foundation.TypedEventHandler<TreeView, TreeViewSelectionChangedEventArgs> SelectionChanged; | ||
} | ||
``` | ||
|
||
# Appendix | ||
<!-- Anything else that you want to write down for posterity, but | ||
that isn't necessary to understand the purpose and usage of the API. | ||
For example, implementation details. --> | ||
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. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SelectionModel class, in addition to
SelectedItems
also hasSelectedItem
. Maybe we could add that here too since we support single selection. On the other hand, we wouldn't gain much by adding that as you can also just get the item at index 0.