Repository navigation
Description
Title
Win11 Theming of Controls - Changes in Controls
Background and motivation
The current WPF controls appear outdated and are not visually consistent with the newly rejuvenated Windows UI. This issue has been identified as the most frequently requested feature [276 Upvotes] (#7555) by the development community. The lack of visually appealing WPF controls makes the platform look outdated. A solution is required to update WPF controls to match the modern Windows UI and improve the aesthetic appeal of WPF applications. The proposal adds relevant properties and methods to the controls classes for using them inside the xaml.
Part of effort - #8655
API Pages
TextBox class
Represents a control that can be used to display or edit unformatted text.
Adding new property PlaceholderText to TextBox
TextBox.Placeholder
This property get or set the placeholder text in the TextBox.
Placeholder text is usually displayed when there is no text input in the TextBox.
Usage
To add a text ("Enter some text") to a TextBox when there is no input.
<TextBox Placeholder="Enter some Text" />
<TextBox>
<TextBox.Placeholder>
<StackPanel Orientation="Horizontal">
<TextBlock Text="" Margin="2" FontFamily="Segoe Fluent Icons" />
<TextBlock Text="Search ..." Margin="2"/>
</StackPanel>
</TextBox.Placeholder>
</TextBox>API Details
public partial class TextBox : System.Windows.Controls.Primitives.TextBoxBase, System.Windows.Markup.IAddChild
{
+ public static readonly System.Windows.DependencyProperty PlaceholderProperty;
+ public object Placeholder { get { throw null; } set { } }
//Protected properties
+ protected override void OnGotFocus(System.Windows.RoutedEventArgs e) { }
+ protected override void OnLostFocus(System.Windows.RoutedEventArgs e) { }
+ protected override void OnTextChanged(System.Windows.Controls.TextChangedEventArgs e) { }
}
PasswordBox class
Represents a control designed for entering and handling passwords.
Adding properties for Placeholder ( other properties will be introduced iteratively )
PasswordBox.Placeholder
This property get or set the placeholder text in the PasswordBox.
Placeholder text is usually displayed when there is no password input in the PasswordBox.
Usage
To add a text ("Enter your password") to a PasswordBox when there is no input password.
<PasswordBox PlaceholderText="Enter your password" />API Details
public sealed partial class PasswordBox : System.Windows.Controls.Control
{
+ public static readonly System.Windows.DependencyProperty PlaceholderProperty;
+ public object Placeholder { get { throw null; } set { } }
}
ComboBox class
Represents a selection control with a drop-down list that can be shown or hidden by clicking the arrow on the control.
Adding properties for Placeholder ( other properties will be introduced iteratively )
ComboBox.Placeholder
This property get or set the placeholder text in the ComboBox.
Placeholder text is usually displayed when there is no password input in the PasswordBox.
Usage
To add a text ("Enter your password") to a PasswordBox when there is no input password.
<ComboBox PlaceholderText="Enter your password" />
<ComboBox ItemsSource="{StaticResource ComboBoxItemsList}"
PlaceholderText="Select City..."
IsEditable="true"
IsReadOnly="true"/>API Details
public sealed partial class PasswordBox : System.Windows.Controls.Control
{
+ public static readonly System.Windows.DependencyProperty PlaceholderProperty;
+ public object Placeholder { get { throw null; } set { } }
}
Risks
No response
cc: @dotnet/dotnet-wpf-triage @pomianowski
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fields☑ Done
Activity
miloush commentedon Jan 9, 2024
There is two different types of additions. One are appearance based (corner radius, backgrounds etc.), one are function based (placeholder text, editing style etc.). Perhaps these could be two different proposals. The functional ones seem reasonable in principle, I am bit uneasy with the appearance ones. Perhaps they might be better off in separate classes, like
ThemeButtonorIconButtonor something.IRelayCommandis missing.What is the reason for
ClientAreaBorder?As for
PassiveScrollViewer, can the property just not be added to normalScrollViewer? What are the "certain events" to be bubbled and does "inactive" mean "not focused"?Win11is probably not an appropriate way to describe the theme and namespace, I am sure there is a name for it akin to Aero.batzen commentedon Jan 9, 2024
Just adding my opinion for the changes to
Button,TextBoxandDataGridas of yet.Button:
We already have styles, i don't see any reason to add an
Appearanceproperty.Why not just provide different styles for different buttons?
99% (guessed) of buttons are regular buttons, why should every button instance loaded a plethora of triggers for the 1% case?
The same applies to the proposed
Iconproperty.DataGrid:
I don't think that column specific stuff belongs in
DataGrid.What if i have different checkbox columns that should behave differently?
TextBox:
Whats the purpose of
IsTextSelectionEnabled? We already can make it read-only.Same as for button and Icon.
Whats the purpose of
TemplateButtonCommand?General:
The general direction of changes seems to be to extend controls with niche properties that blow up the complexity of the templates/styles.
Has anyone considered memory and performance for these changes?
singhashish-wpf commentedon Jan 16, 2024
@miloush @batzen
Thanks a lot for your feedback and responses.
As of now we have a choice of adding more properties and functionality to the existing controls or to provide new controls in a different namespace or controls with different names (Specialized controls eg: ThemedButton or namespaced button eg: win11: button).
I am organizing my thoughts like below, please feel free to add any criteria which is missed and should be accounted for.
dipeshmsft commentedon Feb 26, 2024
I have updated the proposal above. The initial proposal was generated after the integration of the styles and had a lot of properties that were not needed.
@batzen
Agreed. Hence, we decided to remove these from button and have two separate styles, one for standard and other for accent button, similar to WinUI.
As of now, we have removed the properties from DataGrid, but can you provide/point to a code which showcases this.
IsTextSelectionEnabled was not needed. Similarly, we removed Icon property.
TemplateButtonCommand, was there to allow customization when clicking the clear button. However, we have made it internal for now, and provide the default functionality to the clear button.
@miloush
For now, this is not included. Probably it can be added to ScrollViewer, but this will be considered later.
This manages the padding for the window. When using WindowChrome to extend into non-client area, this can be used to automatically fill the client area. I do think, we can provide this functionality by default, but I need to do some more experiments for this.
MikeHillberg commentedon Feb 27, 2024
There's a
PlaceholderTextproperty here now onTextBoxandPasswordBox. I thinkComboBoxis an important one to have as well.batzen commentedon Feb 27, 2024
@dipeshmsft
Different CheckBox-Columns might:
IsEnabledIsVisibleFor example in our codebase we have a DataGrid that's capable of displaying hierarchical data. As our solution is solely based on the data source (ICollectionView) and there are zero modifications to the DataGrid itself, we have to show/hide content in cells based on their data. Parent rows might not have a visible checkbox (or vice versa).
How should that even work technically as CheckBoxColumn already has those properties?
Which style has precedence?
If i want to have the same styles for all CheckBoxColumns i can simply inherit from it and set the desired defaults there.
If the desired outcome is to simplify the sharing of defaults/settings for DataGridColumns (instead of inheritance) then the right place would be DataGridColumn and not DataGrid with various, but limited, amounts of defaults for selected column types.
dipeshmsft commentedon Feb 27, 2024
Got it, that is a legitimate use case, that's why we have removed the extra properties on DataGrid.
12 remaining items
dipeshmsft commentedon Feb 29, 2024
Currently the check is that when the textbox or password box has some non zero content, the placeholder becomes invisible.
miloush commentedon Feb 29, 2024
By the way the example with stackpanel and textblocks can be done using textblock and runs.
I was going to put in some more scenarios in case that helps convincing people:
(I am sticking to the reasonable ones)
@batzen from the proposal it was unclear whether the visibility is part of the TextBlock, in which case you could restyle/retemplate it. From the code it seems that it is based on content, but in a scary way, see here (used in template here). I can see now how this was getting tricky for RTB. It should probably done using triggers in the template instead. I mean currently if I read the code correctly, the implementation removes any binding applied to the
PlaceholderTextproperty.Since we have it an object now, the TextBlock will be presumably automatically created. I don't think we need a template property, but to achieve some of the points above including @batzen's scenario, I think we need a style property applied to the container (easier than to the content), like
PlaceholderStyleorPlaceholderContainerStylewhich is also in charge of the visibility.(Unrelated to the issue: I do want to point people to the "clear button" implementation which I also find problematic, currently it is such that it doesn't need to go through API approval)
batzen commentedon Feb 29, 2024
@miloush Indeed.
The code for placeholder and clear is extremely problematic.
Changes like setting the caret position on focus are concerning too.
@dipeshmsft
Can you clarify why placeholder and clear are solved in code behind?
For example:
Is there a different issue for the clear functionality? Then i could add my feedback there.
I see. What about my other concerns?
miloush commentedon Feb 29, 2024
Perhaps we should keep this issue for the public API changes approval and open issues for the implementations?
dipeshmsft commentedon Feb 29, 2024
@miloush @batzen, with Win11 theming the approach that we are taking is to achieve the correct Win11 styles with minimal API changes and have parity with WinUI in terms of style and behaviors.
We want to work iteratively to allow more customizations for developers.
We would like to take these issues in next iterations of API proposals.
I think WinUI has this behavior, so we kept it the same way.
Regarding the implementations, thanks for both your inputs. We will look into how to handle Placeholder and Clear in a better way, but some of issues will be resolved ( some properties and methods in the branch are present as a result on integration of themes, we will remove things that are not necessary ).
@batzen can you clarify the following,
I think we can address this in the next iterations, right ?
Also, I don't understand what you mean by this -
batzen commentedon Feb 29, 2024
@dipeshmsft
I wouldn't loose the customization as i am using my own implementation, but it would be nice if i could just switch to the built in implementation from WPF once it's ready.
If the default implementation in WPF isn't flexible enough to incorporate such customizations it won't be adopted.
We should have a look at existing implementations for everything that should be added to WPF to make those implementations obsolete/no longer needed.
I think it's a good idea to get ideas from WinUI, but we should also take into account solutions from existing WPF libraries.
In case of placeholder and clear button you can have a look at https://github.com/MahApps/MahApps.Metro/blob/develop/src/MahApps.Metro/Controls/Helper/TextBoxHelper.cs
It's not perfect there, but it's way more flexible than the current proposed implementation.
Same as above. I think it's a good idea to have a look at WinUI, but at the same time that shouldn't be the only source.
WPF is used more widely than WinUI and after trying WinUI a few times already i still very much prefer WPF. Especially because it's way more flexible/customizable, easier to debug, easier to diagnose etc..
In the current implementation branch inside OnGotFocus of TextBox the CaretIndex is changed to be at the end of the text.
I don't know why this was added, but it might break existing apps. The behavior was always that the CaretIndex did not change when loosing/getting focus.
It's just unexpected to see such changes being made.
dipeshmsft commentedon Mar 1, 2024
@miloush @batzen , I think that adding a
PlaceholderVisiblewill give us enough flexibility to handle the custom behvaiours of Placeholder property.Customizing style of Placeholder ( like colour, italics, etc. ), providing buttons, etc. can be done using the Placeholder object.
What are your thoughts on this ? Will this cover the scenarios ?
miloush commentedon Mar 1, 2024
PlaceholderVisibleis unclear. Either it is read-only in which case it should beIsPlaceholderVisibleor it is settable, in which casePlaceholderVisibilityof typeVisibilitywould be better (and easier for implementation and faster).Yes once you have an object, you can do the customization in there.
I agree that visibility is probably the only important thing behavior-wise. Associated Style or Template property could take care of that, but I admit we do have a precedence here too, like
DataGrid.GridLinesVisibility/HeadersVisibility/PlaceholderVisibility,DataGridRow.DetailsVisibilityetc.Neme12 commentedon Apr 10, 2024
I would just a global setting somewhere to set the default control styles (classic, win11, maybe win10 or other windows versions, etc). Or maybe per window. And add the styles to the default resource dictionary so that even if people don't use the global setting, they can use the appropriate ThemeResource on individual buttons and other controls to change their styles anyway. But there's no need to add anything like a new Appearance property IMO - WPF already has styling.
dipeshmsft commentedon May 20, 2025
Closing this as this wouldn't be taken forward, and Placeholder property is being tracked by another API Proposal.