tags:

views:

141

answers:

1

I have a list which contains some controls, including an expander. Within the expander is another list, which I want to overlay the outer list. Here's a simple repo:

<Page.Resources>
  <x:Array x:Key="array1" Type="sys:String">
     <sys:String>item 1</sys:String>
     <sys:String>item 2</sys:String>
     <sys:String>item 3</sys:String>
  </x:Array>
  <DataTemplate x:Key="buttonTemplate">
     <Button Content="{Binding}"/>
  </DataTemplate>
  <DataTemplate x:Key="expanderItem">
     <StackPanel>
        <Expander Header="Options">
           <Canvas>
              <StackPanel Panel.ZIndex="999" Background="Red">
                 <Label>A1
                 </Label>
                 <Label>A2
                 </Label>
                 <Label>A3
                 </Label>
                 <Label>A4
                 </Label>
              </StackPanel>
           </Canvas>
        </Expander>
        <Label BorderBrush="Black" BorderThickness="2" Content="{Binding}"/>
     </StackPanel>
  </DataTemplate>
  </Page.Resources>
 <Grid>
    <ListBox ItemsSource="{StaticResource array1}" ItemTemplate="{StaticResource expanderItem}"/>
 </Grid>

When the expander gets opened, the inner labels get rendered at the same level as the label in the same DataTemplate and the contents later items in the list. I have tried moving the Panel.ZIndex up to the panel with no change.

If I add the following style:

  <Style TargetType="{x:Type Expander}">
     <Style.Triggers>
        <Trigger Property="IsExpanded" Value="True">
           <Setter Property="Panel.ZIndex" Value="999"/>
        </Trigger>
     </Style.Triggers>
  </Style>

It will properly overlay items in the SAME list item, but still renders intermixed with contents from later list items.

(I suspect this is a fairly obvious layout problem, but I have not been able to find it.)

A: 

You could try writing a converter that sets the ZIndex in the datatemplate based on the index of the item in the list. The interesting thing with this would be making sure everything updates correctly as items are added / removed.

Do you need the expander to be independent of layout?

Max Palmer
I'm not quite sure what you mean by independent of layout.I need the expander to overlay other items in this section of the screen, but positioned relative to the item's location in the list... does that make sense?
Ben Von Handorf
Yes, that makes sense. (I just meant that when the expander is expanded it does not affect layout, but appears overlaid on the other items, you could of course have it affect layout and cause the other items to be pushed down).What do you think of the converter idea? Does it seem plausible?
Max Palmer