Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Style BasedOn suddenly not working

These simple styles just stopped working out of the blue. They worked fine until today.

<Style x:Key="textColumnElementStyle" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}">
    <Setter Property="Padding" Value="5,1" />
</Style>

<Style x:Key="textColumnEditingElementStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
    <Setter Property="Padding" Value="2,0" />
</Style>

These both shows errors on the BasedOn property.

The resource "{x:Type TextBlock}" could not be resolved.
The resource "{x:Type TextBox}" could not be resolved.

If I copy and pase one of the styles right next to itself, there is no error on the pasted style.

<Style x:Key="noErrorOnThisStyle" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}">
    <Setter Property="Padding" Value="5,1" />
</Style>

<Style x:Key="textColumnElementStyle" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}">
    <Setter Property="Padding" Value="5,1" />
</Style>

<Style x:Key="textColumnEditingElementStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
    <Setter Property="Padding" Value="2,0" />
</Style>
like image 897
Monstieur Avatar asked Feb 24 '26 03:02

Monstieur


1 Answers

In fact in your case the BasedOn attribute is not needed. Just write

<Style x:Key="textColumnElementStyle" TargetType="{x:Type TextBlock}">
    <Setter Property="Padding" Value="5,1" />
</Style>

<Style x:Key="textColumnEditingElementStyle" TargetType="{x:Type TextBox}">
    <Setter Property="Padding" Value="2,0" />
</Style>

When BasedOn is not set, BasedOn point to the default style of the type specified by the TargetType attribute.

Regards

Claude

like image 167
Claude Catonio Avatar answered Feb 26 '26 22:02

Claude Catonio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!