-
Notifications
You must be signed in to change notification settings - Fork 706
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 InputScope Property To NumberBox #3186
Add InputScope Property To NumberBox #3186
Conversation
I have no idea how to set a default value for an InputScope type in the IDL to 'Number' since InputScope is a class that only has a parameterless constructor and requires the Names property to be set see how 'To change the input scope in code'. This may not be supported? It looks like TextBox itself defaults to null. If someone confirms this isn't possible I guess the work-around is to set the value in OnApplyTemplate(). |
@robloo You could set the default value in the NumberBox constructor. If you set it in OnApplyTemplate() you could end up overwriting the custom value supplied by a developer (without further checks, for example). Furthermore, if you set in in the NumberBox constructor, it acts as the de-facto default value as NumberBox.InputScope will be set even if the NumberBox has only be constructed as a standalone object and not yet added to the visual tree (so no Loaded event raised or OnApplyTemplate() called). It will also make sure custom values set by developers will take precedence over the default value which is what we want. (NumberBox, for example, also sets its NumberFormatter in the constructor. We would do the following for the InputScope API.) |
@Felix-Dev Yes, not sure why I was thinking to put it in the OnApplyTemplate() now -- if I would have thought it through it will be fine in the constructor even before the TextBox is materialized. I'll go ahead and set the default in the constructor if you also can't think of how to do this in the IDL. |
@robloo Yeah, right now I don't know how to do it it purely in the IDL either so I would just go with the constructor approach here. |
The other option, which I think I like better, would be to leave the property null and put a setter in the default style which sets it to number. That way a controls library could change the default for their customers with an updated style. |
// Note that InputScope is a class that cannot be set to a default value within the IDL. | ||
winrt::InputScopeName inputScopeName = winrt::InputScopeName(winrt::InputScopeNameValue::Number); | ||
winrt::InputScope inputScope = winrt::InputScope(); | ||
inputScope.Names().Append(inputScopeName); |
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.
Names [](start = 15, length = 5)
I'm not that familiar with inputScope, does this mean that you can apply multiple input scopes? like you can have number and currency at the same time.
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.
does this mean that you can apply multiple input scopes?
Yes, you can apply multiple name values to the same input scope.
It's certainly an interesting design decision, one which I've never understood myself. However, my assumption has always been it's for the cases where the user can switch the keyboard. It simply limits what keyboards you are allowed to switch between. You might have to reach out to the Windows team to understand the thinking here though. I don't recall ever seeing documented reasons why this is a collection.
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.
@MikeHillberg do you happen to know?
Good idea, that is a cleaner approach. |
<Style TargetType="local:NumberBox">
<Setter Property="InputScope" Value="Number" /> I'm getting a XAML compile error "The TypeConverter for "InputScope" does not support converting from a string". This works fine in C# but looks like another one of those random missing features for C++ developers. Edit: Actually I can't explain why this doesn't work considering setting the InputBox TextBox's InputScope to Number works just fine. |
hmm and the property types are the same right? @fabiant3 is there something we need to to in the IDL to get the type conversion to work? |
dev/NumberBox/NumberBox.cpp
Outdated
{ | ||
// Sets the default value of the InputScope property. | ||
// Note that InputScope is a class that cannot be set to a default value within the IDL. | ||
winrt::InputScopeName inputScopeName = winrt::InputScopeName(winrt::InputScopeNameValue::Number); |
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.
we prefer using auto and const for the local variable types.
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.
Not a problem, should I pursue this now though or wait for potential work-arounds setting in the default style?
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 just did it now so hopefully we can close this. There is no response on work-arounds for the XAML bugs.
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
If direct conversion does not work, you can provide a custom conversion function essentially using x:Bind syntax. @RealTommyKlein |
@fabiant3 This is a change to a templated control, x:Bind isn't supported in templates. I think we probably could using binding with a converter, however I'm not sure we should publish a new converter to work around this, given that setting the default from the constructor seems to work alright? |
@StephenLPeters Can you check and see what the TextBox implementation is doing as you can set |
I wasn't able to repro the error you're seeing with an |
Thanks for looking into this tommy, I confirmed that in my test app, if I add a second copy of my templated control to my page I get the same error the MUX controls test app is getting. @MikeHillberg or @Austin-Lamb do you know why input scope is behaving weirdly here? @robloo I think we should go back to setting the default value in the constructor. |
Should this be considered a bug to be closed with WinUI 3? I can't imagine this behavior is an optimization. |
I think so, but I'm hoping other team members might have a better idea what is going on. |
This reverts commit 3262fd0.
@StephenLPeters I reverted the last commit, should be ready |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
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.
Add InputScope Property To NumberBox
Adds the following API to NumberBox
Motivation and Context
Closes #2710 , relates to #3158
Also relates to the previous discussions in #1912 and PR #2605 where the InputScope was fixed to Number.
How Has This Been Tested?
Screenshots (if appropriate):