locked
Help with Trigger inside of nested listbox templates... RRS feed

  • Question

  • Hi all,

    i've got a situation that i'm not able to wrap my head around...

    I've got 2 listboxes - the first is a simple version - wrappanel layout, with images inside.  This has  a basic template that styles on IsSelected property.

    2nd listbox is composed in a hierarchy.  1rst level panel is Stackpanel (with listboxes for each item), thenWrappanel (Horiz) for nested listboxes panel, with images layed out in this final level.

    Now,  i'm applying the same Style (with controltemplate inside) for both the simple listbox (#1) and the nested listboxes in example #2.

    the style seems to 'style' both instances BUT in the 2nd (nested) instance the triggers stop working, specifically what i need is the 'hilite' on selected.  I added a SelectionChange handler on the listbox itself, and items are definitely getting selected - i just can't get a visual to trigger!

    Code Snippet

    <ControlTemplate.Triggers>
             <Trigger Property="IsSelected" Value="True">
                    <Setter Property="Background"     Value="#CCCCCC" />
                     <Setter Property="BorderBrush" Value="Aqua" />
             </Trigger>             
    </ControlTemplate.Triggers>



    can't for the life of me figure out why - here's the whole Style:

    Code Snippet

    <Style x:Key="listItemStyle" TargetType="{x:Type ListBoxItem}">
         <Setter Property="Background" Value="Transparent" />       
         <Setter Property="Template">
              <Setter.Value>
                  <ControlTemplate TargetType="{x:Type ListBoxItem}">
                        <Border SnapsToDevicePixels="True" HorizontalAlignment="Stretch"                                     VerticalAlignment="Stretch" Background="{TemplateBinding Background}"
                            BorderBrush="#666666"  CornerRadius="6" BorderThickness="1">
                              <ContentPresenter />
                        </Border>
                        <ControlTemplate.Triggers>
                              <Trigger Property="IsSelected" Value="True">
                                  <Setter Property="Background" Value="#CCCCCC" />
                                  <Setter Property="BorderBrush" Value="Aqua" />
                              </Trigger>             
                        </ControlTemplate.Triggers>
                  </ControlTemplate>
            </Setter.Value>
        </Setter>         
    </Style>




    happy to post whole code if necessary....  any help... muchos gracias

    -bigshiny90
    Friday, June 22, 2007 3:06 AM

All replies

  • hmmm... some additional info on the problem.

    I changed my Trigger to "IsMouseOver" and the trigger works as expected.  So this leads me to believe that something else is going on though i can't quite figure it.  The parent listbox SelectionChanged event shows the proper image name as Selected!  but no Trigger happiness...  with IsSelected  :_)

    any ideas would be extremely helpful.. i'm supposing that in the nested nature of this example, something is blocking the Selection process from getting down to the lonely ListBoxItems deep down.  but don't really know what to look for now...

    bigshiny
    Friday, June 22, 2007 5:29 AM