2013-07-04 2 views
1

이러한 단순한 스타일은 파란색으로 작동하지 않습니다. 그들은 오늘까지 잘 일했다.Style BasedOn이 갑자기 작동하지 않습니다.

<Style x:Key="textColumnElementStyle" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}"> 
    <Setter Property="Padding" Value="5,1" /> 
</Style> 

<Style x:Key="textColumnEditingElementStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}"> 
    <Setter Property="Padding" Value="2,0" /> 
</Style> 

이 모두는 BasedOn 재산에 오류를 보여줍니다.

The resource "{x:Type TextBlock}" could not be resolved. 
The resource "{x:Type TextBox}" could not be resolved. 

스타일 중 하나를 복사하여 그 옆에 바로 붙여 넣으면 붙여 넣기 스타일에 오류가 없습니다.

<Style x:Key="noErrorOnThisStyle" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}"> 
    <Setter Property="Padding" Value="5,1" /> 
</Style> 

<Style x:Key="textColumnElementStyle" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}"> 
    <Setter Property="Padding" Value="5,1" /> 
</Style> 

<Style x:Key="textColumnEditingElementStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}"> 
    <Setter Property="Padding" Value="2,0" /> 
</Style> 
+0

그것은 유일한 차이점을 밝혀는 키'noErrorOnThisStyle'의 존재입니까? –

+0

예. 스타일을 몇 줄 위나 아래로 선언하기 만하면 오류가 사라집니다. 또한 TextBox를 기반으로하는 두 개의 유사한 스타일의 경우 TextBox를 확인할 수없고 다른 하나는 해결할 수 없다는 점에 유의하십시오. – Monstieur

+0

유형이 스택 패널 인 경우에도 동일한 문제가 있습니다. 나는 또한 2012 년 대 v3을 사용하고 있습니다. update3 – gavin

답변

1

실제로 귀하의 경우 BasedOn 속성은 필요하지 않습니다. 그냥 쓰기

<Style x:Key="textColumnElementStyle" TargetType="{x:Type TextBlock}"> 
    <Setter Property="Padding" Value="5,1" /> 
</Style> 

<Style x:Key="textColumnEditingElementStyle" TargetType="{x:Type TextBox}"> 
    <Setter Property="Padding" Value="2,0" /> 
</Style> 

BasedOn이 설정되지 않은 경우 BasedOn은 TargetType 속성에 지정된 유형의 기본 스타일을 지정합니다.

감사

클로드

+2

지금 막 멈춘 이유에 대해 대답하지 않습니다. 이 코드는 YEARS에서 잘 작동했습니다. 최근에 VS2012 업데이트 3을 설치했습니다. – Monstieur

+0

기본 스타일은 현재 스타일과 같지 않으며 afaik'BasedOn = "{StaticResource {x : Type TextBlock}}" "은 현재 스타일을 사용합니다. –

관련 문제