종속성 속성에 DataGridRow
색상을 어떻게 설정 합니까?DataGrid
RowBackground
<Style TargetType="{x:Type DataGrid}" x:Key="EmployeeDataGridStyle">
<Setter Property="RowBackground" Value="White"/>
<Setter Property="AlternatingRowBackground" Value="LightCyan"/>
...
</Style>
<Style TargetType="{x:Type DataGridRow}" x:Key="EmployeeDataGridRowStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridRow}">
<Border x:Name="DGR_Border"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background = { ??? //set this to the datagrid rowbackground }
>
...
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal_AlternatingRow">
<Storyboard>
<ColorAnimation
Storyboard.TargetName="DGR_Border"
Storyboard.TargetProperty="Background.Color"
Duration="0"
To="{ ??? // AlternatingRowBackground color that is set in the datagrid
>
...
DataGridRow
템플릿 의 색상을 DataGrid
RowBackgroundColor
속성으로 설정하고 시각적 상태를 사용 AlternatingRowColor
하여 DataGrid
. 어떻게해야합니까?
에 바인딩 RowBackground
의는 DataGrid
사용하여 수행 할 수 있습니다 RelativeSource
바인딩.
Background="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=RowBackground}"
그러나 속성 ColorAnmination
에 대한 두 번째 바인딩은 의도적To
으로 불가능 합니다.
동적 리소스 참조 또는 데이터 바인딩 식을 사용하여 Storyboard 또는 애니메이션 속성 값을 설정할 수 없습니다 . ControlTemplate 내부의 모든 것은 스레드로부터 안전해야하고, 타이밍 시스템은 스레드로부터 안전하도록 FreezeStoryboard 개체를 만들어야하기 때문입니다. 스토리 보드 또는 하위 타임 라인에 동적 리소스 참조 또는 데이터 바인딩식이 포함 된 경우 스토리 보드를 고정 할 수 없습니다. 고정 및 기타 Freezable 기능에 대한 자세한 내용은 Freezable 개체 개요를 참조하십시오 .
AlternatingRowBackground
위와 같은 방식으로 애니메이션과 분리하여 바인딩 할 수 있습니다 .
Background="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=AlternatingRowBackground}"
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다