2012-06-08 3 views
1

다음은 아래 보이는 것과 유사한 바인딩 오류가 발생하는 TabItem 스타일의 일부입니다.컨트롤 템플릿 바인딩 오류

어떻게 코드를 정리할 수 있습니까?

오류

System.Windows.Data Error: 40 : BindingExpression path error: 'HoverForeground' property not found on 'object' ''TabItem' (Name='')'. BindingExpression:Path=HoverForeground; DataItem='TabItem' (Name=''); target element is 'GlyphButton' (Name='HideButton'); target property is 'Foreground' (type 'Brush') 

TabItem의 스타일

<Style x:Key="OrangeTabItemStyle" TargetType="{x:Type TabItem}"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type TabItem}"> 
       <Border AllowDrop="true" ToolTip="{Binding DisplayName}"> 
        <Border Name="Border" Background="Transparent" BorderBrush="Transparent" BorderThickness="1,1,1,0" CornerRadius="2,2,0,0"> 
         <DockPanel x:Name="TitlePanel" TextElement.Foreground="{StaticResource FileTabTextBrush}"> 
       ******    <ctrl:GlyphButton x:Name="HideButton" 
         DockPanel.Dock="Right" 
         GlyphForeground="Transparent" 
         HoverBackground="{StaticResource ToolWindowButtonHoverActiveBackgroundBrush}" 
         HoverBorderBrush="{StaticResource ToolWindowButtonHoverActiveBorderBrush}" 
       *****   HoverForeground="{StaticResource ToolWindowButtonHoverActiveGlyphForegroundBrush}" 
         PressedBackground="{StaticResource ToolWindowButtonPressedBackgroundBrush}" 
         PressedBorderBrush="{StaticResource ToolWindowButtonPressedBorderBrush}" 
         PressedForeground="{StaticResource ToolWindowButtonPressedActiveGlyphForegroundBrush}" 
         HoverBorderThickness="1" PressedBorderThickness="1" Margin="3,2,3,4" 
         Command="{Binding CloseCommand}" 
         CommandParameter="{Binding}" 
         ToolTip="Close"> 
           <Path x:Name="CloseButtonStroke" Width="10" Height="8" Stretch="Uniform" 
             Data="F1 M 0,0 L 2,0 5,3 8,0 10,0 6,4 10,8 8,8 5,5 2,8 0,8 4,4 0,0 Z" 
          Fill="{Binding Path=(TextElement.Foreground), RelativeSource={RelativeSource Self}}" /> 
          </ctrl:GlyphButton> 

          <ContentPresenter x:Name="Content" HorizontalAlignment="Stretch" Margin="4,2,4,4" VerticalAlignment="Stretch" 
               RecognizesAccessKey="true" ContentSource="Header" /> 
         </DockPanel> 
        </Border> 
        <Border.InputBindings> 
         <KeyBinding Command="{Binding CloseCommand}" Key="F4" Modifiers="Control" /> 
        </Border.InputBindings> 
       </Border> 
       <ControlTemplate.Triggers> 
        <Trigger Property="IsMouseOver" Value="true"> 
         <Setter TargetName="Border" Value="{StaticResource FileTabIsMouseOverBorderBackgroundBrush}" Property="Background" /> 
         <Setter TargetName="Border" Value="{StaticResource FileTabIsMouseOverBorderBrush}" Property="BorderBrush" /> 
         <Setter TargetName="TitlePanel" Value="{StaticResource FileTabIsMouseOverTextForegroundBrush}" Property="TextElement.Foreground" /> 
         <Setter TargetName="HideButton" Value="{StaticResource FileTabIsMouseOverGlyphForegroundBrush}" Property="GlyphForeground" /> 
        </Trigger> 
        <Trigger Property="IsSelected" Value="True"> 
         <Setter Property="Panel.ZIndex" Value="1" /> 
         <Setter TargetName="Border" Value="{StaticResource FileTabIsSelectedBackgroundBrush}" Property="Background" /> 
         <Setter TargetName="Border" Value="{StaticResource FileTabIsSelectedBackgroundBrush}" Property="BorderBrush" /> 
         <Setter TargetName="Border" Property="BorderThickness" Value="0" /> 
         <Setter TargetName="Border" Property="Padding" Value="0,1,0,0" /> 
         <Setter TargetName="HideButton" Property="Margin" Value="3" /> 
         <Setter TargetName="TitlePanel" Value="{StaticResource FileTabIsSelectedTextForegroundBrush}" Property="TextElement.Foreground" /> 
         <Setter TargetName="HideButton" Value="{StaticResource FileTabIsSelectedGlyphForegroundBrush}" Property="GlyphForeground" /> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

GlyphButton 제어

public class GlyphButton : Button 
{ 

    public static readonly DependencyProperty HoverForegroundProperty = DependencyProperty 
     .Register("HoverForeground", typeof(Brush), typeof(GlyphButton)); 

    public Brush HoverForeground 
    { 
     get { return (Brush) GetValue(HoverForegroundProperty); } 
     set { SetValue(HoverForegroundProperty, value); } 
    } 

    // other properties similar to this omitted.... 
} 

편집 - GlyphButton 스타일

<Style TargetType="{x:Type ctrl:GlyphButton}"> 
    <Setter Property="Width" Value="{Binding Path=ActualHeight, RelativeSource={RelativeSource Self}}" /> 
    <Setter Property="Foreground" Value="{Binding Path=GlyphForeground, RelativeSource={RelativeSource Self}}" /> 
    <Setter Property="Background" Value="Transparent" /> 
    <Setter Property="BorderBrush" Value="Transparent" /> 
    <Setter Property="BorderThickness" Value="1" /> 
    <Setter Property="Focusable" Value="false" /> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type ctrl:GlyphButton}"> 
       <Border 
        Name="Border" Background="{TemplateBinding Background}" 
        BorderBrush="{TemplateBinding BorderBrush}" 
        BorderThickness="{TemplateBinding BorderThickness}"> 
        <ContentPresenter /> 
       </Border> 
       <ControlTemplate.Triggers> 
        <Trigger Property="IsMouseOver" Value="true"> 
         <Setter TargetName="Border" Value="{Binding HoverBackground , RelativeSource={RelativeSource TemplatedParent}}" 
           Property="Background" /> 
         <Setter TargetName="Border" Value="{Binding HoverBorderBrush , RelativeSource={RelativeSource TemplatedParent}}" 
           Property="BorderBrush" /> 
         <Setter TargetName="Border" Value="{Binding HoverBorderThickness , RelativeSource={RelativeSource TemplatedParent}}" 
           Property="BorderThickness" /> 
         <Setter Value="{Binding HoverForeground , RelativeSource={RelativeSource TemplatedParent}}" 
           Property="Foreground" /> 
        </Trigger> 
        <Trigger Property="IsPressed" Value="True"> 
         <Setter TargetName="Border" Value="{Binding PressedBackground , RelativeSource={RelativeSource TemplatedParent}}" 
           Property="Background" /> 
         <Setter TargetName="Border" Value="{Binding PressedBorderBrush , RelativeSource={RelativeSource TemplatedParent}}" 
           Property="BorderBrush" /> 
         <Setter TargetName="Border" Value="{Binding PressedBorderThickness , RelativeSource={RelativeSource TemplatedParent}}" 
           Property="BorderThickness" /> 
         <Setter Value="{Binding PressedForeground , RelativeSource={RelativeSource TemplatedParent}}" 
           Property="Foreground" /> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
+0

그 스타일의 HoverForeground에 대한 참조가 없습니다. – Phil

+1

Path = HoverForeground 인 바인딩식이 표시되지 않습니다. _this_ XAML에서 오류가 발생 했습니까? –

+1

GlyphButton의 기본 스타일이 있습니까? –

답변

0

Setter Value = "{바인딩 HoverForeground, RelativeSource = {RelativeSource TemplatedParent}}"-이 요소의 템플릿 부모에 대한 참조를 가져 와서 속성 HoverForeground를 찾으십시오. 귀하의 controltemplate에 대한 템플릿 부모는 첫 번째 스타일의 탭 컨트롤입니다 ...

+0

나는 이해할 수 없다. 나는 너를 고쳐야한다고 말하고 있니? – Berryl

+0

예, 필요한 속성은 GlyphButton 자체에 있으므로 RelativeSource = {RelativeSource Self}} "오류가 수정되었습니다. – Berryl