[UWP] AccessKey support on VisualElement and TabbedPage #2061
Conversation
case NotifyCollectionChangedAction.Replace: | ||
if (e.NewItems != null) | ||
foreach (var c in e.NewItems) | ||
(c as Page).PropertyChanged += OnChildPagePropertyChanged; |
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.
I wonder if there is a way to not sub/unsub this event and still achieve this effect. Its expensive to sub PropertyChanged as it triggers a fair bit...
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.
Good point. However - is it that big difference compared to other property change handling.
One thought could be to try to handle this in xaml with converters or something? Haven't looked alot into that yet though.
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.
Overall looks great. This will be super useful.
Did you look into implementing IsAccessKeyScope
at the layout level at all?
Not sure if that will be translatable from a forms layout scope to UWP so was curious if you had looked into it much with this change?
Element.CurrentPage = page; | ||
} | ||
|
||
protected void UpdateAccessKey(TextBlock control) { |
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.
I realize there are subtle differences but can the UpdateAccessKey
that's in VisualElementRenderer and TabbedPageRenderer be generalized into a reusable internal static method?
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.
Created AccessKeyHelper which should take care of this now.
case NotifyCollectionChangedAction.Remove: | ||
case NotifyCollectionChangedAction.Replace: | ||
if (e.NewItems != null) | ||
foreach (var c in e.NewItems) |
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.
These might go away because of Jason's comments but if not can you change to for (int i
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.
Sure. Curious though - why is that preferred? :-)
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.
There are cases where foreach vs for doesn't matter and there are cases where it does matter as far as Memory and performance (especially on the Mono side). Generally the for will perform better or the same as foreach
In a case like this with so few items, where it happens very infrequently and it's UWP it's most likely irrelevant but it's more about a consistent pattern we use throughout the code base. So unless there's a compelling reason (other than just being easier) to use foreach we just use for (int i
@PureWeen thanks for the feedback! I haven't looked into implementing access key scope in this PR. I read about how it works in UWP but I reasoned that as a first step we only wanted basic support for access keys. |
@henricm Yea I looked at the Localization as well seeing what made sense. My thought here is that since this is all settable from forms as a string you can just use the Localization APIs through forms to set things to a Localized value.. If you use the bindings to set these properties then localization can just be achieved that way As far as the native support for localization that feels like it would just be a different issue as that's just about setting the Uid of the elements right? Opening up a platform API that lets you set the Uid on the native control would just be generally useful it seems but outside the scope of this issue. As far as IsAccessKeyScope. My thoughts would be that if it's easy enough to apply the property at the layout level and then translate this down into UWP go for it but if the devil in the details makes this too tricky then a separate issue would suffice.. Is it as easy as adding a property to Xamarin.Forms.Layout then having LayoutRenderer on UWP set the property? Or am I being short sighted? |
@PureWeen sounds good regarding localization and I will definitely have a look at access key scope. Hopefully later this week. |
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.
Looks great, just need to reduce the duplicate code and I think it's ready.
@@ -429,5 +460,65 @@ void UpdateBarIcons() | |||
Control.InvalidateMeasure(); | |||
} | |||
} | |||
void UpdateToolbarPlacement() |
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.
Spaces -> Tabs
85a05b0
to
909f070
Compare
@PureWeen I wrestled a bit with adding |
@henricm yea :-/ I hoped it'd be just be an easy win but I'm not surprised it wasn't. Changes look good |
Fixes xamarin#1672 by adding AccessKey, AccessKeyPlacement and horizontal and vertical offset properties to Windows specific VisualElement class. Also handles AccessKeys for tabbed pages (ContentPage).
Refs xamarin#1672 and fixes issue with AccessKey not being updated after tabbed page and its children had been created. The problem was that the Reset event in OnPagesChange wasn't handled correctly. We now add listeners to the child pages of the tabbed page which makes sure AccessKey gets updated if user makes changes to tab object.
Updated foreach-loop and replaced spaces with tabs.
909f070
to
bdaa38a
Compare
@hartez the duplicate has been removed and everything is rebased as of today so please take another look when you have time. Thanks! |
Description of Change
Fixes #1672 by adding AccessKey, AccessKeyPlacement and horizontal
and vertical offset properties to Windows specific VisualElement class.
Also handles AccessKeys for tabbed pages (ContentPage).
API Changes
Added:
enum AccessKeyPlacement
for specifying placement of the access key tooltip.Behavioral Changes
When you set AccessKey property button, tab etc will be able to execute its action when user presses the Alt-button. When the Alt-button is pushed once, access key tooltips will be displayed.
PR Checklist