2009-11-11 7 views
2

요소 트리거를 재정의하려면 텍스트 상자를 클릭 할 때 부모 테두리의 속성이 변경됩니다.부모 속성을 변경하는 WPF 트리거

그러나 상위 대상 이름이 인식되지 않습니다. 이 같은

<Style x:Key="customstyle" TargetType="{x:Type local:customcontrol}"> 
    <Setter Property="Background" Value="{StaticResource DownGradientBrush}"/> 
    <Setter Property="BorderBrush" Value="{StaticResource DownGradientBorder}"/> 
    <Setter Property="Foreground" Value="{StaticResource TextBoxForeground}"/> 
    <Setter Property="HorizontalAlignment" Value="Center"/> 
    <Setter Property="VerticalAlignment" Value="Center"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type local:customcontrol}"> 
       <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}"> 
        <Grid> 
         <Grid.RowDefinitions> 
          <RowDefinition/> 
          <RowDefinition/> 
         </Grid.RowDefinitions> 
         <Grid.ColumnDefinitions> 
          <ColumnDefinition Width="*"/> 
          <ColumnDefinition Width="15"/> 
         </Grid.ColumnDefinitions> 
         <Border Grid.Column="0" 
           Grid.RowSpan="2" 
           HorizontalAlignment="Stretch"> 
    <TextBox x:Name="TextBox" 
      Grid.Column="0" 
      Grid.RowSpan="2" 
      Text="{Binding RelativeSource={x:Static RelativeSource.TemplatedParent}, Path=Value}" 
      Width="Auto" 
      Height="Auto"> 
     <TextBox.Style> 
      <Style BasedOn="{StaticResource StyleTextBox}" TargetType="{x:Type TextBox}"> 
       <Style.Triggers> 
        <Trigger Property="IsFocused" Value="True"> 
         <Setter TargetName="Bd" 
           Property="Background" 
           Value="{StaticResource CustomGradientBorder}" /> 
        </Trigger> 
        <Trigger Property="IsFocused" Value="True" /> 
       </Style.Triggers> 
      </Style> 
     </TextBox.Style> 
    </TextBox> 
    </Border> 
    </Grid> 
    </Border> 
    <ControlTemplate.Triggers> 
     <Trigger Property="IsFocused" Value="True"> 
      <Setter TargetName="Bd" Property="BorderBrush" Value="{StaticResource CustomGradientBorder}" /> 
     </Trigger> 
    </ControlTemplate.Triggers> 
    </ControlTemplate> 
    </Setter.Value> 
    </Setter> 
</Style> 

답변

6

변화를 : 여기에 코드 샘플입니다

<ControlTemplate.Triggers> 
    <Trigger Property="IsFocused" Value="True" SourceName="TextBox"> 
    <Setter TargetName="Bd" Property="BorderBrush" Value="{StaticResource CustomGradientBorder}" /> 
    </Trigger> 
</ControlTemplate.Triggers> 
+0

덕분에, 그게 확실히했다 :) – immuner

관련 문제