Wpf 由DynamicSource绑定时未应用样式

Wpf 由DynamicSource绑定时未应用样式,wpf,xaml,Wpf,Xaml,我有点困惑。我正在创建一个示例,并为我的文本框创建了一个默认模板。我试图归档的是将样式应用于边框,并在其中指定BorderBrush。应用此样式时,此 <Style TargetType="{x:Type newLibrary:MyTextBox}"> <Setter Property="SnapsToDevicePixels" Value="True" /> <Setter Property="KeyboardNavigation.TabNav

我有点困惑。我正在创建一个示例,并为我的文本框创建了一个默认模板。我试图归档的是将样式应用于边框,并在其中指定BorderBrush。应用此样式时,此

 <Style TargetType="{x:Type newLibrary:MyTextBox}">
<Setter Property="SnapsToDevicePixels"
        Value="True" />

<Setter Property="KeyboardNavigation.TabNavigation"
        Value="None" />
<Setter Property="FocusVisualStyle"
        Value="{x:Null}" />
<Setter Property="MinWidth"
        Value="120" />
<Setter Property="MinHeight"
        Value="20" />
<Setter Property="AllowDrop"
        Value="true" />
<Setter Property="Template">
  <Setter.Value>
    <ControlTemplate TargetType="{x:Type newLibrary:MyTextBox}">
      <Border Name="Border"
              CornerRadius="2"
              Padding="2"
              BorderThickness="1">
        <Border.Background>
          <SolidColorBrush Color="{DynamicResource ControlLightColor}" />
        </Border.Background>

        <VisualStateManager.VisualStateGroups>
          <VisualStateGroup x:Name="CommonStates">
            <VisualState x:Name="Normal" />
            <VisualState x:Name="Disabled">
              <Storyboard>
                <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
                                              Storyboard.TargetProperty="(Panel.Background).
                (SolidColorBrush.Color)">
                  <EasingColorKeyFrame KeyTime="0"
                                       Value="{StaticResource DisabledControlLightColor}" />
                </ColorAnimationUsingKeyFrames>
              </Storyboard>
            </VisualState>
            <VisualState x:Name="ReadOnly">
              <Storyboard>
                <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
                                              Storyboard.TargetProperty="(Panel.Background).
                (SolidColorBrush.Color)">
                  <EasingColorKeyFrame KeyTime="0"
                                       Value="{StaticResource DisabledControlDarkColor}" />
                </ColorAnimationUsingKeyFrames>
              </Storyboard>
            </VisualState>
            <VisualState x:Name="MouseOver" />
          </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <ScrollViewer Margin="0"
                      x:Name="PART_ContentHost" />

      <Border.Style>
        <Style TargetType="{x:Type Border}" >
          <Setter Property="Border.BorderBrush" >
            <Setter.Value>
              <MultiBinding Converter="{StaticResource myconv}">
                <Binding/>
                <Binding/>
              </MultiBinding>
            </Setter.Value>
          </Setter>
        </Style>
      </Border.Style>
      </Border>
    </ControlTemplate>
  </Setter.Value>
</Setter>

不幸的是,当我试图提取此样式(稍后覆盖它)时,它不起作用-边框不会变为红色

  <Style TargetType="{x:Type newLibrary:MyTextBox}">
<Setter Property="SnapsToDevicePixels"
        Value="True" />

<Setter Property="KeyboardNavigation.TabNavigation"
        Value="None" />
<Setter Property="FocusVisualStyle"
        Value="{x:Null}" />
<Setter Property="MinWidth"
        Value="120" />
<Setter Property="MinHeight"
        Value="20" />
<Setter Property="AllowDrop"
        Value="true" />
<Setter Property="Template">
  <Setter.Value>
    <ControlTemplate TargetType="{x:Type newLibrary:MyTextBox}">
      <Border Name="Border"
              CornerRadius="2"
              Padding="2"
              BorderThickness="1"
              Style="{DynamicResource VisualStyle}">
        <Border.Background>
          <SolidColorBrush Color="{DynamicResource ControlLightColor}" />
        </Border.Background>

        <VisualStateManager.VisualStateGroups>
          <VisualStateGroup x:Name="CommonStates">
            <VisualState x:Name="Normal" />
            <VisualState x:Name="Disabled">
              <Storyboard>
                <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
                                              Storyboard.TargetProperty="(Panel.Background).
                (SolidColorBrush.Color)">
                  <EasingColorKeyFrame KeyTime="0"
                                       Value="{StaticResource DisabledControlLightColor}" />
                </ColorAnimationUsingKeyFrames>
              </Storyboard>
            </VisualState>
            <VisualState x:Name="ReadOnly">
              <Storyboard>
                <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
                                              Storyboard.TargetProperty="(Panel.Background).
                (SolidColorBrush.Color)">
                  <EasingColorKeyFrame KeyTime="0"
                                       Value="{StaticResource DisabledControlDarkColor}" />
                </ColorAnimationUsingKeyFrames>
              </Storyboard>
            </VisualState>
            <VisualState x:Name="MouseOver" />
          </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <ScrollViewer Margin="0"
                      x:Name="PART_ContentHost" />


      </Border>
    </ControlTemplate>
  </Setter.Value>
</Setter>


告诉我们更多关于您的两种款式的位置?如果您尝试将
x:Key=“customBorder”
放在主样式上,然后在第二个样式中使用此
BasedOn=“{Static
DynamicResource customBorder}”
。HTHthey位于themes\generic.xaml中。事实上,我正试图取代。。。。。但它不起作用。如果没有牵引力,它会按预期工作