2009-04-27 20 views
14

क्षमा करें अगर इससे पहले पूछा गया है, लेकिन मुझे जो कुछ भी मिल रहा है, उससे संबंधित समाधानों का समाधान नहीं मिल रहा है, या Google पर।डब्ल्यूपीएफ सूची बॉक्स चयन रंग

मेरे आवेदन में मैं शब्दों को नए दस्तावेज़ संवाद, वस्तुओं के बाईं ओर सूची और दाईं ओर पाठ के साथ दाईं ओर सूची बनाने की कोशिश कर रहा हूं। जब आप किसी आइटम का चयन करते हैं तो 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> 
संबंधित मुद्दे