2009-04-27 8 views
14

죄송합니다. 이전에 질문을 받았지만 팝업 된 관련 질문이나 Google에서 해결책을 찾지 못했습니다.WPF 목록 상자 선택 색상

내 응용 프로그램에서 단어의 새 문서 대화 상자를 다시 만들려고합니다. 항목 왼쪽에는 목록이 표시되고 오른쪽에는 텍스트가있는 아이콘이 표시됩니다. Word에서는 마우스를 올리면 주황색 그라디언트가 표시되고 항목을 선택하면 어두운 그라디언트가 나타납니다. 아이템을 선택하면 배경색을 변경하는 것을 제외하고는 대부분 재현했습니다.

<ListView Margin="236,34,17,144" Name="listView1" HorizontalContentAlignment="Stretch"> 
     <ListView.ItemsPanel> 
      <ItemsPanelTemplate> 
       <UniformGrid Columns="5" IsItemsHost="True" VerticalAlignment="Top" > 
       </UniformGrid> 
      </ItemsPanelTemplate> 
     </ListView.ItemsPanel> 
     <ListView.ItemTemplate> 
      <DataTemplate > 
       <StackPanel HorizontalAlignment="Center" Width="auto"> 
        <Image Source="images/document32.png" HorizontalAlignment="Center"/> 
        <TextBlock Text="{Binding}" HorizontalAlignment="Center" /> 
       </StackPanel> 
      </DataTemplate> 
     </ListView.ItemTemplate> 
     <ListView.ItemContainerStyle> 
      <Style TargetType="{x:Type ListViewItem}" >     
       <Style.Triggers> 
        <Trigger Property="IsSelected" Value="true"> 
         <Setter Property="Foreground" Value="Yellow" /> 
         <Setter Property="Background" Value="Orange" /> 
        </Trigger> 
        <Trigger Property="IsMouseOver" Value="true"> 
         <Setter Property="Foreground" Value="Black" /> 
         <Setter Property="Background"> 
          <Setter.Value> 
           <LinearGradientBrush EndPoint="0.5,1" StartPoint="1,0"> 
            <GradientStop Color="#d3e7ff" Offset="0.986"/> 
            <GradientStop Color="#b0d2fc" Offset="0.5"/> 
            <GradientStop Color="#8ec1ff" Offset="0.51"/> 
           </LinearGradientBrush> 
          </Setter.Value> 
         </Setter> 
        </Trigger> 

       </Style.Triggers> 
      </Style> 
     </ListView.ItemContainerStyle> 
    </ListView> 

그래서 내가 갈거야 모양을 만들고, 위에 마우스를하지, 나는 목록보기에서 항목을 선택하면 그것으로 글꼴의 텍스트를 변경합니다 : 여기이를 만드는 데 사용하고 코드입니다 노란색이지만 배경을 기본 파란색에서 주황색으로 변경하는 것을 거부하며 이상적으로는 그래디언트 그라디언트가 적용되며 채워진 색상이 아닙니다. 어떤 도움을 주셔서 감사합니다.

답변

31

시스템 색상 키를 무시하는 것처럼 할 수있는 몇 가지 해킹이 있지만이를 달성하기 위해 새 템플릿을 제공하는 것이 가장 좋습니다. 여기에 함께 넣어 꽤 좋은 찾고 있어요 :

<Style x:Key="ListboxItemStyle" TargetType="{x:Type ListBoxItem}"> 
    <Setter Property="Margin" Value="1,2,1,1"/> 
    <Setter Property="HorizontalAlignment" Value="Stretch" /> 
    <Setter Property="Background" Value="{StaticResource NormalItemBackground}" /> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type ListBoxItem}"> 
       <Grid> 
        <Border Background="{TemplateBinding Background}" /> 
        <Border Background="#BEFFFFFF" Margin="3,1"> 
         <Grid> 
          <Grid.RowDefinitions> 
           <RowDefinition /> 
           <RowDefinition /> 
          </Grid.RowDefinitions> 
          <Border Margin="2,1,2,0" Grid.Row="0" Background="#57FFFFFF" /> 
         </Grid> 
        </Border> 
        <ContentPresenter Margin="8,5" /> 
       </Grid> 
       <ControlTemplate.Triggers> 
        <MultiTrigger> 
         <MultiTrigger.Conditions> 
          <Condition Property="IsMouseOver" Value="True" /> 
          <Condition Property="IsSelected" Value="False"/> 
         </MultiTrigger.Conditions> 
         <Setter Property="Background" Value="{StaticResource HotItemBackground}" /> 
        </MultiTrigger> 
        <Trigger Property="IsSelected" Value="True"> 
         <Setter Property="Background" Value="{StaticResource SelectedItemBackground}" /> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
<Style x:Key="ListBoxStyle" TargetType="{x:Type ListBox}"> 
    <Setter Property="ItemContainerStyle" Value="{DynamicResource ListboxItemStyle}" /> 
    <Setter Property="Margin" Value="3,3,2,1" /> 
</Style>