在特定子树中应用我自己的 XAML 样式

Apply my own XAML style within a particular subtree

我有以下风格。如下所示,效果很好:

    <StackPanel Orientation="Vertical">
      <StackPanel.Resources>
        <Style TargetType="TextBlock">
          <Setter Property="Padding" Value="0 0 0 0.3cm" />
          <Setter Property="Height" Value="Auto" />
          <Setter Property="VerticalAlignment" Value="Stretch" />
        </Style>
      </StackPanel.Resources>
      <TextBlock Text="Hello"/>
      <TextBlock Text="World"/>
    </StackPanel>

问题来了。我真正想做的是在第三个位置定义此样式,然后以上述工作示例的方式在各种 StackPanel 中使用它,包括它们的子级,但不是在所有 StackPanel 中。这是我试过的。它给出了构建错误:

<Window.Resources>
  <Style x:Key="TextBlockWithBottomMargin" TargetType="TextBlock">
    <Setter Property="Padding" Value="0 0 0 0.3cm" />
    <Setter Property="Height" Value="Auto" />
    <Setter Property="VerticalAlignment" Value="Stretch" />
  </Style>
</Window.Resources>
<Grid>
  <TabControl>
    <!-- omitting some XAML here -->
    <TabItem Header="Help" >
    <StackPanel Orientation="Vertical">
      <StackPanel.Resources>
        <Style Binding="{StaticResource TextBlockWithBottomMargin}"></Style> <!-- build error on this line -->
      </StackPanel.Resources>
      <TextBlock Text="Hello"/>
      <TextBlock Text="World"/>
    </StackPanel>
    <!-- lots more xaml here -->

使用下面的代码在一个级别创建样式:

<StackPanel.Resources>
     <Style TargetType="TextBlock" BasedOn="{StaticResource TextBlockWithBottomMargin}">
           <Setter .......      
     </Style>
</StackPanel.Resources>