Padding via Style -> Setter does not apply

If you specify the element itself, then everything works

<TextBlock Style="{StaticResource expanderTextBlockStyle}" Padding="10 0" .... 

A lot of TextBlock elements, so I apply styles like this:

 <Style x:Key="expanderTextBlockStyle"> <Setter Property="Control.Padding" Value="10 0"></Setter> <Setter Property="Control.FontWeight" Value="Normal"></Setter> <Setter Property="Control.FontSize" Value="14"></Setter> </Style> 

The FontSize and FontWeight properties work, but Padding does not!

Tell me what am I doing wrong?

  • Object--DispatcherObject--DependencyObject--Visual--UIElement--FrameworkElement--TextBlock - I do not see in the inheritance hierarchy of the Control class, why should it be used? - tym32167
  • @ tym32167 inherited ObjectDispatcher - ObjectDependency - ObjectVisual - UIElement - FrameworkElement-Control namespace System.Windows.Controls - there is The rest, everything works - ZIBER MINSK
  • I understand it can be changed through the Template (ControlTemplate)? I am still studying) and do not know all the subtleties ... - ZIBER MINSK
  • one
    TextBlock not a Control successor. Specify in the style of TargetType="TextBlock" and set the setter just Property="Padding" - Andrey NOP
  • @ AndreiNOP Thank you! - ZIBER MINSK

1 answer 1

TextBlock is not a Control successor. Specify in the style of TargetType = "TextBlock" and set the setter just Property = "Padding"