'WPF understand why textbox template into textblock still editable
In my project i have created a template for my textbox, for test purpose i simplify it to this code:
<Window.Resources>
<Style x:Key="test" TargetType="{x:Type TextBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<TextBlock Text="{TemplateBinding Text}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<TextBox Style="{StaticResource test}" Grid.Row="2" Height="50" Width="200" Text="test">
</TextBox>
</Grid>
For what i understand, template erase how should be represented the textbox and show what i put in the template.
so when i put 'test' to the text TextBox, in reality it put it to the text Textbloc inside the textbox.
textbloc should be readonly, but on running if i clic on the label and tap on my keyboard, it still print key at the start of text (only add char at the start of text)...
(with binding it's editing the binding property...)
With a IsReadOnly="True" on the actual textbox it work as expected, but i don't understand why i need to do it.
I try on net6.0-windows and net5.0-windows, same result.
Is anymone understanding what i missing ?
Thank's for your time
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
