Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the zindex of datatemplate's in a longlistselector

I have a longlistselector with certain images that i add in this longlistselector. I also change the margins of this image to make the image go up or down and so on. But i want to put this image infront of another image in this longlistselector. I have tried using Canvas.Zindex. I have tried setting it at the grid level, at image level and at the top level of of the longlistselector.() But it still doesn't work. Does anybody have some idea's? You can find my code below:

<phone:LongListSelector 

        x:Name="SouthLongListselector" 
        VerticalAlignment="Bottom"
        ItemsSource="{Binding Cards}"
        Canvas.ZIndex="{Binding Layer}"
        SelectionChanged="SouthLongListselector_SelectionChanged"   
        LayoutMode="Grid"
        GridCellSize="50,200" 
        Margin="0,0,0,-26"
        >

    <phone:LongListSelector.ItemTemplate >  
        <DataTemplate>
            <Grid
                Background="Transparent" 
                Margin="{Binding GridOffset}"
                Height="150"
                Width="110"                      
                >
                <!-- add image here-->
                <Image 
                        Source="{Binding Image}"
                        >
                </Image>

            </Grid>

        </DataTemplate>
    </phone:LongListSelector.ItemTemplate>                
</phone:LongListSelector>
like image 558
user3375515 Avatar asked Mar 03 '14 15:03

user3375515


People also ask

Does z-index work on position positions?

Note: z-index only works on positioned elements (position: absolute, position: relative, position: fixed, or position: sticky) and flex items (elements that are direct children of display: flex elements). Here we see that an element with greater stack order is always above an element with a lower stack order:

What is z-index in HTML?

Definition and Usage. The z-index property specifies the stack order of an element. An element with greater stack order is always in front of an element with a lower stack order. Note: z-index only works on positioned elements (position: absolute, position: relative, position: fixed, or position: sticky). Default value:

What is the difference between z-index and stack order?

An element with greater stack order is always in front of an element with a lower stack order. Note: z-index only works on positioned elements (position: absolute, position: relative, position: fixed, or position: sticky) and flex items (elements that are direct children of display:flex elements).

Do I need z-index to float an element?

You most probably don't need z-index to do that. You can use relative and absolute positioning. I advise you to take a better look at css positioning and the difference between relative and absolute positioning... I saw you're setting position: absolute; to an element and trying to float that element.


1 Answers

I have only used WPF but xaml should be the same.

I don't see your Canvas the you are referencing anywhere so Canvas.ZIndex. So I think what you want is to set the panel of the list to be a canvas and then set the Zindex for the times in the list.

<phone:LongListSelector.ItemsPanel>
    <ItemsPanelTemplate>
        <Canvas/>
    </ItemsPanelTemplate>
</phone:LongListSelector.ItemsPanel>
<phone:LongListSelector.ItemTemplate >  
        <DataTemplate>
            <Grid
                Canvas.ZIndex"{Binding Layer}"
                Background="Transparent" 
                Margin="{Binding GridOffset}"
                Height="150"
                Width="110"                      
                >
                <!-- add image here-->
                <Image 
                        Source="{Binding Image}"
                        >
                </Image>

            </Grid>

        </DataTemplate>
    </phone:LongListSelector.ItemTemplate>   
like image 67
Michael Shaffer Avatar answered Nov 14 '22 23:11

Michael Shaffer