-
Notifications
You must be signed in to change notification settings - Fork 705
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
NumberBox should respect Background/Foreground properties #2998
Comments
Seems reasonable to me, do you have thoughts on the open question? |
@StephenLPeters As outlined above I think the There is, however, issue #1925 which currently suggests that the As such, in my opinion it really comes down to how developers would expect the
If developers expect it to affect the background of both the input field and the spin buttons, then that raises the question how the NumberBox.TextForeground, if set, would take precedence over NumberBox.Foreground for the foreground color of the input field (Numberbox.TextBackground and NumberBox.Background would act analog to this). If, however, developers would be fine if the NumberBox.Background API only allows configuring the background of the input field, then we can use the What do you think? |
I think So right now I would hook everything up to use background. In the future it might make sense to have separate SpinButtonBackground/BorderBrush/BorderThickness properties. |
@robloo Yes, I agree. Applying the How do yow view the suggestion of Here are two examples: <muxc:NumberBox MinWidth="200" x:Name="TestNumberBox"
Foreground="DodgerBlue"
Background="#FF404040"
Header="NumberBox"
SpinButtonPlacementMode="Inline"
Value="100"/> <muxc:NumberBox MinWidth="200" x:Name="TestNumberBox"
Foreground="DodgerBlue"
Background="#FF404040"
TextForeground="Green"
TextBackground="Black"
Header="NumberBox"
SpinButtonPlacementMode="Inline"
Value="100"/> |
I realize we should do something like This same concept should then be applied to the input TextBox itself. We should have a TextBox style that can be used to customize the foreground and background that you are trying to do above. That will allow a lot more styling as well. We shouldn't be adding new |
@robloo The issue I'm seeing here is that some developers want to to easily change the foreground color of the input field of the NumberBox depending on the actual value. This doesn't strike me as a corner case so it should be something which can be easily achievable: I would consider having to create custom TextBox styles just for changing the text foreground color from red to green (and vice-versa) as not being developer-friendly. Just as developers today can use the That said, depending on how proposal #784 will be handled, your suggested
There is proposal #2789 which asks for the icons of the spin buttons to be customizable. I am mentioning this because the discussion there showed that there is some concern that providing a completely free styling experience could end up harmful to the customer experience and thus might not be something the team will greenlight. Your idea would give developers even more freedom than my initial suggestion in that proposal so I'm not sure how that would be looked upon by the WinUI team. |
Yes, you are certainly correct and there is always a trade-off with ease-of-use and functionality. Are there any other controls that use TextForeground? I can't recall any. Creating a new property like this is a bit counter-intuitive considering all existing controls. We should really follow convention and I can't help but think a general-purpose solution would be better for all the cases we aren't considering as well. It also beautifully solves the spin button styling topic. Overall, it prevents developers from having to re-template the entire control which is the main concern and also doesn't require custom resource definitions (often poorly documented). A simple style isn't so hard to write and is very concise in markup. This has been the standard convention since the beginning. XAML-related tech has always had a steeper learning curve as it's necessary for it to be as powerful as it is. <NumberBox.TextBoxStyle>
<Style TargetType="TextBox">
<Setter Property="Foreground"
Value="Green" />
</Style>
</NumberBox.TextBoxStyle>
This is counter to the look-less control principles that WPF started with and we are still working with today. I realize I'm getting more-and-more alone in that voice though.
|
The issue here really is only the special NumberBox spin button inline state and how we interpret
That is the true. Given the current NumberBosx setup a developer would first create a red and green foreground style of a TextBox. Then, they would have to create red and green foreground styles of the TextBox style used by the NumberBox when it is in compact mode. Finally, they could create a function binding to the suggested The question for me then is, and I won't be able to answer that, how common the scenario of changing the NumberBox's input field foreground color dynamically at runtime would be. If it turns out to be quite a common scenario, then I believe we should add dedicated As for your suggestion adding Style properties for the spin buttons: You could add that to proposal #2789 as yet another idea what WinUI should offer developers to style the spin buttons. For example, there is no need to create APIs like |
@Felix-Dev I certainly understand your points. If it was up to me, I would go the styling route first (it's more powerful and fits convention). If after some time a lot of people are complaining then I would consider TextForeground-type properties. But before adding them to NumberBox I would consider other similar scenarios in other controls and how they are handled. Anyway, that's my 2 cents. We probably need more feedback from others or for Microsoft to weigh in directly at this point. It's great you take up working on these types of things! |
Is this issue just withering on the vine? Or has something that accomplishes this been implemented, but not linked to this issue? |
I think this was fixed with #4469 |
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
Describe the bug
Currently, the
NumberBox
control does not respect itsBackground
andForeground
APIs like theTextBox
control does it. See the following XAML and the resulting UI:Expected behavior
Open questions
How should these two APIs affect the NumberBox control when it is in
SpinButtonPlacementMode.Inline
? Developers might want to dynamically change the foreground color of the NumberBox's input field depending on the actual value of the NumberBox. For example, color green for positive values and color red for negative values. As such, theNumberBox.Foreground
API should only affect the foreground of the input box and not the foreground of the spin buttons as well. Consequently, theNumberBox.Background
property should just affect the background of the input field too:If developers also need to modify the foreground and/or background color of the spin buttons in inline mode, lightweight styling can be used. I have opened proposal #2844 which suggests adding a whole new set of NumberBox specific theme resources to give developers plenty of flexibility in styling their NumberBox controls.
Version Info
Newest WinUI master builds.
The text was updated successfully, but these errors were encountered: