2011-03-31 2 views
8

목록 요소의 선택 스타일로 내 WPF 응용 프로그램에 문제가 있습니다. 모든 목록 난 WPF 진한 파란색 배경 색상과 흰색 텍스트 색상을 얻을.WPF - WPF 응용 프로그램의 목록에 대한 선택 스타일을 기본 Windows 7 스타일로 변경하십시오.

  1. 왜 기본 Windows 7 선택 스타일 (예를 들어, Windows 탐색기에서 파일 선택)하지 윈도우 7에 WPF 응용 프로그램에서 기본 선택 스타일?

  2. WPF의 선택 스타일을 기본 Windows 7 Aero 스타일로 어떻게 변경합니까?

지금까지 나는 이것을 글로벌 리소스 사전에 가지고 있습니다. 하지만 브러시를 반올림하여 테두리를 비슷하게 보이게하려면 테두리가 필요합니다. 기본 Windows 7 선택 스타일을 어떻게 적용 할 수 있는지에 대한 아이디어 나 다른 제안 사항을 확장하는 방법은 무엇입니까?

<LinearGradientBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" StartPoint="0,0" EndPoint="0,1"> 
<LinearGradientBrush.GradientStops> 
    <GradientStop Offset="0" Color="#FFE3F4FC"/> 
    <GradientStop Offset="0.38" Color="#FFD8EFFC"/> 
    <GradientStop Offset="0.38" Color="#FFBEE6FD"/> 
    <GradientStop Offset="1" Color="#FFA6D9F4"/> 
</LinearGradientBrush.GradientStops> </LinearGradientBrush> 

<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black"></SolidColorBrush> 

답변

5

Windows 7 모양을 ListBox 에 적용하는 방법을 설명하는 블로그 항목이 있습니다. ListView 및 TreeView도 다루지 만 Windows 7보기를 완전히 주제로하지는 않습니다. 당신이 포함해야 것

관련 리소스입니다 : 그것은이 작동 것이라고 코드를보고 보인다

<!-- Hover Brushes --> 
<LinearGradientBrush x:Key="HoverBackgroundBrushKey" 
         StartPoint="0,0" 
         EndPoint="0,1"> 
    <GradientStop Color="#FCFCFC" 
        Offset="0" /> 
    <GradientStop Color="#EBF3FD" 
        Offset="1" /> 
</LinearGradientBrush> 
<SolidColorBrush x:Key="HoverOuterBorderBrushKey" 
        Color="#B8D6FB" /> 
<SolidColorBrush x:Key="HoverInnerBorderBrushKey" 
        Color="#F2F7FE" /> 

<!-- Selected (Active) Brushes --> 
<LinearGradientBrush x:Key="SelectedActiveBackgroundBrushKey" 
         StartPoint="0,0" 
         EndPoint="0,1"> 
    <GradientStop Color="#DCEBFC" 
        Offset="0" /> 
    <GradientStop Color="#C1DBFC" 
        Offset="1" /> 
</LinearGradientBrush> 
<SolidColorBrush x:Key="SelectedActiveOuterBorderBrushKey" 
        Color="#7DA2CE" /> 
<SolidColorBrush x:Key="SelectedActiveInnerBorderBrushKey" 
        Color="#EBF4FD" /> 

<!-- Selected (Inactive) Brushes --> 
<LinearGradientBrush x:Key="SelectedInactiveBackgroundBrushKey" 
         StartPoint="0,0" 
         EndPoint="0,1"> 
    <GradientStop Color="#F8F8F8" 
        Offset="0" /> 
    <GradientStop Color="#E5E5E5" 
        Offset="1" /> 
</LinearGradientBrush> 
<SolidColorBrush x:Key="SelectedInactiveOuterBorderBrushKey" 
        Color="#D9D9D9" /> 
<SolidColorBrush x:Key="SelectedInactiveInnerBorderBrushKey" 
        Color="#F0F0F0" /> 

<!-- ListBoxItem Style --> 
<Style x:Key="{x:Type ListBoxItem}" 
     TargetType="{x:Type ListBoxItem}"> 
    <Setter Property="BorderThickness" 
      Value="1" /> 
    <Setter Property="Padding" 
      Value="2,0" /> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type ListBoxItem}"> 
       <Grid> 
        <Border x:Name="outerBorder" 
          BorderBrush="{TemplateBinding BorderBrush}" 
          BorderThickness="{TemplateBinding BorderThickness}" 
          CornerRadius="2" 
          SnapsToDevicePixels="true"> 
         <Border x:Name="innerBorder" 
           Background="{TemplateBinding Background}" 
           BorderThickness="1" 
           CornerRadius="1" 
           Padding="{TemplateBinding Padding}" 
           SnapsToDevicePixels="true"> 
          <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
               VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
               SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> 
         </Border> 
        </Border> 
       </Grid> 
       <ControlTemplate.Triggers> 
        <Trigger Property="IsMouseOver" 
           Value="true"> 
         <Setter TargetName="outerBorder" 
           Property="BorderBrush" 
           Value="{StaticResource HoverOuterBorderBrushKey}" /> 
         <Setter TargetName="innerBorder" 
           Property="Background" 
           Value="{StaticResource HoverBackgroundBrushKey}" /> 
         <Setter TargetName="innerBorder" 
           Property="BorderBrush" 
           Value="{StaticResource HoverInnerBorderBrushKey}" /> 
        </Trigger> 
        <Trigger Property="IsSelected" 
           Value="true"> 
         <Setter TargetName="outerBorder" 
           Property="BorderBrush" 
           Value="{StaticResource SelectedActiveOuterBorderBrushKey}" /> 
         <Setter TargetName="innerBorder" 
           Property="Background" 
           Value="{StaticResource SelectedActiveBackgroundBrushKey}" /> 
         <Setter TargetName="innerBorder" 
           Property="BorderBrush" 
           Value="{StaticResource SelectedActiveInnerBorderBrushKey}" /> 
        </Trigger> 
        <MultiTrigger> 
         <MultiTrigger.Conditions> 
          <Condition Property="IsSelected" 
             Value="true" /> 
          <Condition Property="Selector.IsSelectionActive" 
             Value="false" /> 
         </MultiTrigger.Conditions> 
         <Setter TargetName="outerBorder" 
           Property="BorderBrush" 
           Value="{StaticResource SelectedInactiveOuterBorderBrushKey}" /> 
         <Setter TargetName="innerBorder" 
           Property="Background" 
           Value="{StaticResource SelectedInactiveBackgroundBrushKey}" /> 
         <Setter TargetName="innerBorder" 
           Property="BorderBrush" 
           Value="{StaticResource SelectedInactiveInnerBorderBrushKey}" /> 
        </MultiTrigger> 
        <Trigger Property="IsEnabled" 
           Value="false"> 
         <Setter Property="Foreground" 
           Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" /> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

<!-- ListViewItem Style --> 
<Style x:Key="{x:Type ListViewItem}" 
     TargetType="{x:Type ListViewItem}" 
     BasedOn="{StaticResource {x:Type ListBoxItem}}" /> 

<!-- Supporting TreeViewItem Resources --> 
<PathGeometry x:Key="TreeArrow"> 
    <PathGeometry.Figures> 
     <PathFigureCollection> 
      <PathFigure IsFilled="True" 
         StartPoint="0 0" 
         IsClosed="True"> 
       <PathFigure.Segments> 
        <PathSegmentCollection> 
         <LineSegment Point="0 6" /> 
         <LineSegment Point="6 0" /> 
        </PathSegmentCollection> 
       </PathFigure.Segments> 
      </PathFigure> 
     </PathFigureCollection> 
    </PathGeometry.Figures> 
</PathGeometry> 
<Style x:Key="ExpandCollapseToggleStyle" 
     TargetType="{x:Type ToggleButton}"> 
    <Setter Property="Focusable" 
      Value="False" /> 
    <Setter Property="Width" 
      Value="16" /> 
    <Setter Property="Height" 
      Value="16" /> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type ToggleButton}"> 
       <Border Width="16" 
         Height="16" 
         Background="Transparent" 
         Padding="5,5,5,5"> 
        <Path x:Name="ExpandPath" 
          Fill="Transparent" 
          Stroke="#FF989898" 
          Data="{StaticResource TreeArrow}"> 
         <Path.RenderTransform> 
          <RotateTransform Angle="135" 
               CenterX="3" 
               CenterY="3" /> 
         </Path.RenderTransform> 
        </Path> 
       </Border> 
       <ControlTemplate.Triggers> 
        <Trigger Property="IsMouseOver" 
           Value="True"> 
         <Setter TargetName="ExpandPath" 
           Property="Stroke" 
           Value="#FF1BBBFA" /> 
         <Setter TargetName="ExpandPath" 
           Property="Fill" 
           Value="Transparent" /> 
        </Trigger> 

        <Trigger Property="IsChecked" 
           Value="True"> 
         <Setter TargetName="ExpandPath" 
           Property="RenderTransform"> 
          <Setter.Value> 
           <RotateTransform Angle="180" 
                CenterX="3" 
                CenterY="3" /> 
          </Setter.Value> 
         </Setter> 
         <Setter TargetName="ExpandPath" 
           Property="Fill" 
           Value="#FF595959" /> 
         <Setter TargetName="ExpandPath" 
           Property="Stroke" 
           Value="#FF262626" /> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

<!-- TreeViewItem Style --> 
<Style x:Key="{x:Type TreeViewItem}" 
     TargetType="{x:Type TreeViewItem}"> 
    <Setter Property="BorderThickness" 
      Value="1" /> 
    <Setter Property="Padding" 
      Value="2,0" /> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type TreeViewItem}"> 
       <Grid> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition MinWidth="19" 
              Width="Auto" /> 
         <ColumnDefinition Width="Auto" /> 
         <ColumnDefinition Width="*" /> 
        </Grid.ColumnDefinitions> 
        <Grid.RowDefinitions> 
         <RowDefinition Height="Auto" /> 
         <RowDefinition /> 
        </Grid.RowDefinitions> 
        <ToggleButton x:Name="expander" 
            Style="{StaticResource ExpandCollapseToggleStyle}" 
            IsChecked="{Binding Path=IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" 
            ClickMode="Press" /> 
        <Border x:Name="outerBorder" 
          Grid.Column="1" 
          BorderBrush="{TemplateBinding BorderBrush}" 
          BorderThickness="{TemplateBinding BorderThickness}" 
          CornerRadius="2" 
          SnapsToDevicePixels="true"> 
         <Border x:Name="innerBorder" 
           Background="{TemplateBinding Background}" 
           BorderThickness="1" 
           CornerRadius="1" 
           Padding="{TemplateBinding Padding}" 
           SnapsToDevicePixels="true"> 
          <ContentPresenter x:Name="PART_Header" 
               ContentSource="Header" 
               HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
               SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> 
         </Border> 
        </Border> 
        <ItemsPresenter x:Name="itemsHost" 
            Grid.Row="1" 
            Grid.Column="1" 
            Grid.ColumnSpan="2" /> 
       </Grid> 
       <ControlTemplate.Triggers> 
        <Trigger Property="IsExpanded" 
           Value="false"> 
         <Setter TargetName="itemsHost" 
           Property="Visibility" 
           Value="Collapsed" /> 
        </Trigger> 
        <Trigger Property="HasItems" 
           Value="false"> 
         <Setter TargetName="expander" 
           Property="Visibility" 
           Value="Hidden" /> 
        </Trigger> 
        <Trigger SourceName="outerBorder" 
           Property="IsMouseOver" 
           Value="true"> 
         <Setter TargetName="outerBorder" 
           Property="BorderBrush" 
           Value="{StaticResource HoverOuterBorderBrushKey}" /> 
         <Setter TargetName="innerBorder" 
           Property="Background" 
           Value="{StaticResource HoverBackgroundBrushKey}" /> 
         <Setter TargetName="innerBorder" 
           Property="BorderBrush" 
           Value="{StaticResource HoverInnerBorderBrushKey}" /> 
        </Trigger> 
        <Trigger Property="IsSelected" 
           Value="true"> 
         <Setter TargetName="outerBorder" 
           Property="BorderBrush" 
           Value="{StaticResource SelectedActiveOuterBorderBrushKey}" /> 
         <Setter TargetName="innerBorder" 
           Property="Background" 
           Value="{StaticResource SelectedActiveBackgroundBrushKey}" /> 
         <Setter TargetName="innerBorder" 
           Property="BorderBrush" 
           Value="{StaticResource SelectedActiveInnerBorderBrushKey}" /> 
        </Trigger> 
        <MultiTrigger> 
         <MultiTrigger.Conditions> 
          <Condition Property="IsSelected" 
             Value="true" /> 
          <Condition Property="Selector.IsSelectionActive" 
             Value="false" /> 
         </MultiTrigger.Conditions> 
         <Setter TargetName="outerBorder" 
           Property="BorderBrush" 
           Value="{StaticResource SelectedInactiveOuterBorderBrushKey}" /> 
         <Setter TargetName="innerBorder" 
           Property="Background" 
           Value="{StaticResource SelectedInactiveBackgroundBrushKey}" /> 
         <Setter TargetName="innerBorder" 
           Property="BorderBrush" 
           Value="{StaticResource SelectedInactiveInnerBorderBrushKey}" /> 
        </MultiTrigger> 
        <Trigger Property="IsEnabled" 
           Value="false"> 
         <Setter Property="Foreground" 
           Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" /> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
+0

. 그러나 WPF 프레젠테이션 프레임 워크에서 기본 OS 스타일을 지원하지 않는다고 Microsoft에 실망합니다. 이것은 DataGrid, TreeView 등과 같은 선택 스타일을 가진 모든 컨트롤러에 대한 템플릿을 만들거나 재정의해야한다는 것을 의미합니까? – chrisva

+0

@chrisva - 맞습니다. 일관된 Windows 7 모양을 원한다면 그 컨트롤을 테마로해야합니다. – CodeNaked

+0

WPF 용 운영 체제의 활성 테마 또는 기본 테마를 연결하는 방법이 없다고 생각합니다. 요점은, 동일한 컨트롤이 N 개의 컨트롤을 가질 수 있다는 것입니다. 개별 컨트롤에 테마를 제공하는 것은 의미가 없습니다. – Mohanavel

관련 문제