Unanswered ListBoxItem styling question

  • Samstag, 14. April 2012 00:26
     
      Enthält Code

    I am using this code to style my list box items when they are selected.  But I don't know how to style them when they are not selected, I know there is a better way of going about styling than this...

            <Style x:Key="myFireListBoxStyle">
                <Style.Resources>
                    <!-- Background of selected item when focused -->
                    <LinearGradientBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
                        <GradientStop Color="#FF606060" Offset="0"/>
                        <GradientStop Color="#FF2F2F2F" Offset="1"/>
                    </LinearGradientBrush>
                    <!-- Background of selected item when not focused -->
                    <LinearGradientBrush x:Key="{x:Static SystemColors.ControlBrushKey}" EndPoint="0.5,1"  MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
                        <GradientStop Color="#FFEBEBEB" Offset="0"/>
                        <GradientStop Color="#FF969696" Offset="1"/>
                    </LinearGradientBrush>
                </Style.Resources>
            </Style>
    Thanks in advance!

Alle Antworten

  • Samstag, 14. April 2012 03:02
     
     

    Do you have Expression Blend? With Expression blend you can right-click on any object and choose Edit Template | Edit a copy and get a copy of the default style for that Element.

    I just happen to have a post on my blog that has the default style in it in case you don't have Expression Blend.
    http://www.wpfsharp.com/2012/03/18/itemscontrol-vs-listbox-vs-listview-in-wpf/

    So you would take the default style and add to it the two LinearGradientBrush elements you have in your post. Then modify the style how you want.

    And if you are going to work with WPF and Styling a lot, get Expression Blend.


    http://www.rhyous.com

  • Sonntag, 15. April 2012 01:32
     
     

    Thanks Rhyous,

    I do have Expression Blend however I wanted to edit the ListBoxItem not the list box itself.  Sorry for not making that clear enough.

    When I right click, edit a copy is disabled.

  • Sonntag, 15. April 2012 11:25
     
     
    Expression Blend -> Make into control - > recording is on -> change the style when move to or leave the listboxitem?

    I'm a 13 years old kid.


    • Bearbeitet KKLEO Sonntag, 15. April 2012 11:25
    •  
  • Dienstag, 24. April 2012 02:32
     
     
    What?