2014-11-21 4 views
1

나를 용서하십시오. 그냥 초보자를 WPF으로 용서하십시오.속성을 설정하면 System.Windows.FrameworkElement.Style 예외가 throw되었습니다.

내 작은 WPF 응용 프로그램을 VS2012에서 디버깅하려고 할 때 예외가 발생했습니다. 아래 스크린 샷을 검토하십시오. 나는 예외가 정확히 무엇인지 알아 내려고 노력했다. 그러나 예외에 대한 자세한 메시지를 얻을 수있는 방법을 찾지 못했습니다. 코드는 XAML의 첫 번째 줄에서 끊어지는 것처럼 보입니다. enter image description here

enter image description here

나는 그것은 내 스타일 DataGridDemoStyle에 나쁜 코드에 의해 발생할 수 있습니다 생각했다. 하지만 어떤 코드가 오류인지 알지 못했습니다. 오류의 InnerException과 같은 세부 정보를 볼 방법이 있습니까?

감사합니다.

업데이트 내가 라인으로 스타일 코드 라인을 확인 후

.

DataGridDemoRowStyle이라는 스타일이 오류를 일으켰습니다. 왜이 스타일로 인해 오류가 발생하는지 알 수 없습니다. 왜냐하면 제가 그것을 제거하기 때문입니다. 오류가 사라집니다. 아래에서 검토하십시오.

<Style x:Key="DataGridDemoStyle" TargetType="{x:Type DataGrid}"> 
     <!--<Setter Property="AlternatingRowBackground" Value="{StaticResource RowBackgroundAlternateBrush}" />--> 
     <!--<Setter Property="BorderBrush" Value="#FF688CAF"/>--> 
     <!--<Setter Property="Background" Value="{DynamicResource bearBrush}" />--> 
     <!--<Setter Property="ColumnHeaderHeight" Value="50" />--> 
     <!--<Setter Property="HeadersVisibility" Value="All" />--> 
     <!--<Setter Property="RowBackground" Value="{StaticResource RowBackgroundBrush}" />--> 
     <!--<Setter Property="AlternationCount" Value="4" />--> 
     <Setter Property="RowStyle" Value="{StaticResource DataGridDemoRowStyle}" /> 

     <!--<Setter Property="RowHeaderWidth" Value="50" />--> 
     <Setter Property="RowHeight" Value="22" /> 
     <Setter Property="HorizontalGridLinesBrush" Value="{StaticResource DataGridHorizontalLinesBrush}" /> 
     <Setter Property="CellStyle" Value="{StaticResource DataGridCellStyle}" /><!----> 

     <Setter Property="ColumnHeaderStyle" Value="{StaticResource DatagridColumnHeaderCustomTemplateStyle}" /> 
    </Style> 
    <!--I don't know why below style will cause the error. If I remove it . the error will gone.--> 
    <Style x:Key="DataGridDemoRowStyle" TargetType="{x:Type DataGridRow}"> 
     <Style.Triggers> 
      <Trigger Property="AlternationIndex" Value="2" > 
       <Setter Property="Background" Value="{StaticResource RowBackgroundAlternationIndex2Brush}" /> 
      </Trigger> 
      <Trigger Property="AlternationIndex" Value="3"> 
       <Setter Property="Background" Value="{StaticResource RowBackgroundAlternationIndex3Brush}" /> 
      </Trigger> 
     </Style.Triggers> 
    </Style> 

DataGridDemoRowStyle 스타일에 문제가 있습니까? 감사.

답변

2

이유를 발견했습니다.

기본 스타일 다음에 하위 스타일을 넣으면. WPF는이를 찾아서로드 할 수 없습니다. 그래서 나는 모든 의존 스타일을 DataGridDemoStyle 앞에 두어야 만한다.

올바른 방법 :

<Style x:Key="substyle1" >..</Style> 
<Style x:Key="substyle2" >..</Style> 
.. 
<Style x:Key="substylen" >..</Style> 
<Style x:Key="mainstyle" > 
    ... 
    <Setter Property="xxx" Value="{StaticResource substylen}" /> 
</style> 

PS : 그것은 XAML을위한 라인으로 준수 선을 보인다. 모든 의존성은 지정된 코드 컴파일 라인 이전에 준비되어야합니다. 나는 그것이 옳은지 몰랐다. 검토해주십시오.

감사합니다.

+0

정확합니다. 주문 문제. –

+0

내 질문을 검토해 주셔서 감사합니다. 좋은 하루 되세요. :) –

+0

괜찮습니다. +1. –

관련 문제