2014-02-24 6 views
4

나는 다음 스타일WPF DataGrid의 스타일

<Style x:Key="DataGridRowStyle1" TargetType="{x:Type DataGridRow}"> 
    <Setter Property="Foreground" Value="#FFB3B3B3"/> 
    <Setter Property="Height" Value="25"/> 
    <Setter Property="HorizontalContentAlignment" Value="Stretch"/> 
    <Setter Property="Template" Value="{DynamicResource DataGridRowControlTemplate1}"/> 
    <Style.Triggers> 
     <Trigger Property="IsSelected" Value="True"> 
      <Setter Property="Background" Value="#FF262626"/> 
     </Trigger> 
     <Trigger Property="ItemsControl.AlternationIndex" Value="0"> 
      <Setter Property="Background" Value="#FF383838"/> 
     </Trigger> 
     <Trigger Property="ItemsControl.AlternationIndex" Value="1"> 
      <Setter Property="Background" Value="#FF333333"/> 
     </Trigger> 
    </Style.Triggers> 
</Style> 

와 데이터 그리드를 가지고 있고 그것은 다음과 같이 나타납니다

enter image description here

DataGrid에 초점 잃을 때 내 문제가 나타납니다

:

enter image description here

내가 어떻게 만들 수 있습니까? 초점과 무관 한 외모?

+0

당신이 완성 된 전체 XAML 스타일을 공유 할 수 있습니까? 좋은 것 같습니다. – bashkan

+0

사용중인 글꼴을 물어 볼 수 있습니까? –

+0

나는 기억할 수 없다, 죄송합니다 –

답변

2

해결 방법을 찾기 전에 DataGrid, DataGridRow 등 의 Focus (IsFocused 트리거)에서 기본 동작이 될 수 없으므로 StyleTrigger for Focus (IsFocused 트리거)를 살펴보십시오. 이없는 경우

,이 같은 이벤트 GotFocus에 대한 EvenTriggersLostFocus을 추가하려고 :

<Window.Resources> 
    <SolidColorBrush x:Key="GotFocusColor" Color="Green" /> 
    <SolidColorBrush x:Key="LostFocusColor" Color="Transparent" /> 

    <Style TargetType="{x:Type DataGridRow}"> 
     <Setter Property="Foreground" Value="#FFB3B3B3"/> 
     <Setter Property="Height" Value="25"/> 
     <Setter Property="HorizontalContentAlignment" Value="Stretch"/> 

     <Style.Triggers> 
      <Trigger Property="IsSelected" Value="True"> 
       <Setter Property="Background" Value="#FF262626"/> 
      </Trigger> 

      <Trigger Property="ItemsControl.AlternationIndex" Value="0"> 
       <Setter Property="Background" Value="#FF383838"/> 
      </Trigger> 

      <Trigger Property="ItemsControl.AlternationIndex" Value="1"> 
       <Setter Property="Background" Value="#FF333333"/> 
      </Trigger> 

      <EventTrigger RoutedEvent="DataGrid.GotFocus"> 
       <BeginStoryboard> 
        <Storyboard> 
         <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background"> 
          <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{StaticResource GotFocusColor}" /> 
         </ObjectAnimationUsingKeyFrames> 
        </Storyboard> 
       </BeginStoryboard> 
      </EventTrigger> 

      <EventTrigger RoutedEvent="DataGrid.LostFocus"> 
       <BeginStoryboard> 
        <Storyboard> 
         <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background"> 
          <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{StaticResource LostFocusColor}" /> 
         </ObjectAnimationUsingKeyFrames> 
        </Storyboard> 
       </BeginStoryboard> 
      </EventTrigger> 
     </Style.Triggers> 
    </Style> 
</Window.Resources> 
+1

팀원 중 한 명이 솔루션을 테스트하고 피드백을 주어야합니다 !! 미안해. 연기. –

+0

@ m.samy : 내 대답이 도움이 되었습니까? 질문이 있습니까? –

+0

WPF MUI App 내부의 DataGrid에 대해이 작업을 해주셔서 감사 드리며, UserControl 내부에 있으므로 UserControl.Resource로 Windows.Resource를 변경했습니다. – BENN1TH

관련 문제