Using setter for TextBlock.Text property breaks some other TextBlocks
See original GitHub issueDescribe the bug
When I define a Style for TextBlock with Setter for Text property, it removes (not even replaces) text on some other TextBlock controls.
To Reproduce Minimal XAML example I’ve came up with:
<Window xmlns="https://github.com/avaloniaui"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:vm="using:TextBlockTextSetterBug.ViewModels"
		xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
		xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
		mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
		x:Class="TextBlockTextSetterBug.Views.MainWindow"
		Icon="/Assets/avalonia-logo.ico"
		Title="TextBlockTextSetterBug">
	<Window.Styles>
		<Style Selector="TextBlock.myautotext">
			<Setter Property="Text" Value="Text from Style" />
		</Style>
	</Window.Styles>
	<Design.Height>200</Design.Height>
	<Design.Width>300</Design.Width>
	<Design.DataContext>
		<vm:MainWindowViewModel/>
	</Design.DataContext>
	<StackPanel>
		<!-- This text IS visible (style works as expected) -->
		<TextBlock Classes="myautotext" />
		
		<!-- This text IS visible (bindings outside DataTemplate are working) -->
		<TextBlock Text="{Binding Greeting}" />
	
		<!-- This text is NOT visible (direct setting of text doesn't work) -->
		<TextBlock Text="Can't see me" />
	
		<!-- Text of items is NOT visible (using explicit DataTemplate changes nothing) -->
		<ListBox Items="{Binding SomeStrings}"/>
	</StackPanel>
</Window>
Expected behavior
TextBlock controls not matching the selector must not be affected.
Screenshots
Expected:

Actual:

Desktop
- OS: Windows 10
- Avalonia 0.10.13 (latest from NuGet)
Additional context Add any other context about the problem here.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:19 (16 by maintainers)
 Top Results From Across the Web
Top Results From Across the Web
Overwrite Text property in a Setter (or a better approach)
I'm struggling with replicating a switch in WPF XAML, where I want to go through some bindings hierarchically and set my Text property...
Read more >Control When the TextBox Text Updates the Source
This topic describes how to use the UpdateSourceTrigger property to control the timing of binding source updates. The topic uses the TextBox ......
Read more >Untitled
Using setter for TextBlock.Text property breaks some other WebDec 5, 2011 · hi For my TextBlock Text, i've declared a MultiBinding with StringFormat...
Read more >Unable to Bind Text to TextBlock in TileGroupHeader
Hi, I am unable to bind the text to TextBlock which is there in TileGroupHeader of TileLayoutControl. It is working when we give...
Read more >TextBox Mask XAML Property - Windows Community Toolkit
The TextBoxMask Property allows a user to more easily enter fixed width text in TextBox control where you would like them to enter...
Read more > Top Related Medium Post
Top Related Medium Post
No results found
 Top Related StackOverflow Question
Top Related StackOverflow Question
No results found
 Troubleshoot Live Code
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free Top Related Reddit Thread
Top Related Reddit Thread
No results found
 Top Related Hackernoon Post
Top Related Hackernoon Post
No results found
 Top Related Tweet
Top Related Tweet
No results found
 Top Related Dev.to Post
Top Related Dev.to Post
No results found
 Top Related Hashnode Post
Top Related Hashnode Post
No results found

The reason is kind of lost in the mists of time, but I think it was done for performance reasons. Reading a CLR (i.e. direct) property is about 40x faster currently than reading a styled property. That combined with:
TextBlocks are very common and there will likely be a lot of themI think lead us to decide that it was worth sacrificing some flexibility for performance.
@grokys Hm, in my opinion this feature shouldn’t be sacrificed. It is something I would expect to just work and does in all other XAML frameworks. That said, I don’t know the performance issues encountered at the time, or if they are still valid. I think this should also be documented some place along with why it was designed this way.
If the styling system is really this slow, and this is still a problem enough to keep Text a direct property, I guess there are more fundamental concerns that should be addressed. WPF can handle this type of thing just fine and it’s performance was well enough – obviously it never ran on all the form factors Avalonia does though.
Overall, this is pretty unintuitive and has/will cause a lot of tricky debugging. I definitely think compile warnings are needed but I think this should just be a StyledProperty for TextBlock (leave TextBox as-is). Optimizations have since been made to the styling system over the years as well.
Finally, are we sure there isn’t more going on?:
There is no way this should ever not work. I guess it is related to the other issue of priority that might be fixed after your PR.