I recently raised #1007 for being able to edit a TreeView. I think that this is probably the correct way of implementing this feature, and will be far more powerful and extend to many other elements of WInUI.
In this issue, I'm proposing that TextBlock (or at the least, a Run within a TextBlock) are made editable. Textblock's are used everywhere in the UI, including within the tree view, in list views, etc. My making the TextBlock editable, we solve this problem everywhere that a developer may want to be able to implement rename functionality in their app.
My current use case is for list view (which also lacks this as I see), and rather than raise a proposal for the list view specifically, I'm thinking in general terms how this can best be implemented.
| Capability | Priority |
| :---------- | :------- |
| This proposal will allow end users to change text in a TextBlock or Run | Must |
| This proposal will mean that WinUI controls can behave in a manner that makes sense in Win32 and macOS | Must |
| Users should be able to rename by clicking and pausing or pressing F2 in a selected item | Could |
| Two way binding on the TextBlock will update the view model when the text is changed | Must |
Examples of this are prevalent in desktop operating systems. It doesn't make sense on touch, but Gnome, Kde, Windows (Win32) and macOS all implement this paradigm.
File Explorer uses F2 and the Context Menu to go into Editable mode for the currently selected item. Touch could use a FlyoutMenu with a rename option if enabled. Perhaps an "IsEditable" on the TextBlock control?
Some Adobe Software allows double clicking a Layer/Item's Text area, to enable in place renaming.
I think TextBlock needs to be kept simple though, it's main purpose is to just display text.
It's pretty straight-forward to have both a textblock and a textbox in a template and swap between the two on clicking the textblock/list item. That's what I've done in the past for these scenarios.
Otherwise, I'd see the inverse being the more practical and having something like TextBox's IsReadOnly have a style option where it doesn't have any of the chrome around it.
I agree with @michael-hawker. Please don't add the ability to edit the TextBlock -- it is not the use case of this control. TextBox is the control to use when you want to edit text. That is a pretty fundamental concept all the way back from the WPF days.
The functionality you are looking for can be done with the TextBox, new styling and changing from IsReadOnly on the DoubleTapped event.
I know this is a separate issue, but it would be nice for the TextBlock to get a Selectable (or similar) property. There have been many times we needed to be able to just highlight and copy the text to paste info in emails or elsewhere.
I know this is a separate issue, but it would be nice for the TextBlock to get a Selectable (or similar) property. There have been many times we needed to be able to just highlight and copy the text to paste info in emails or elsewhere.
@shaggygi You mean IsTextSelectionEnabled="True" - It exists.
@mdtauk > You mean IsTextSelectionEnabled="True" - It exists.
I didn't think this was in WPF? Anyways, I'm glad it will be in WinUI. Thanks for pointing this out.
@mdtauk > You mean IsTextSelectionEnabled="True" - It exists.
I didn't think this was in WPF? Anyways, I'm glad it will be in WinUI. Thanks for pointing this out.
WinUI 3.0 is about UWP XAML - WPF controls are part of dotnet.
If its not part of the WPF TextBlock, you should probably propose it in that repo.
Most helpful comment
I agree with @michael-hawker. Please don't add the ability to edit the TextBlock -- it is not the use case of this control. TextBox is the control to use when you want to edit text. That is a pretty fundamental concept all the way back from the WPF days.
The functionality you are looking for can be done with the TextBox, new styling and changing from IsReadOnly on the DoubleTapped event.