How to set the the zindex of datatemplate's in

2019-02-17 08:20发布

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 bellow:

  <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>

Thanks in advance,

1条回答
放荡不羁爱自由
2楼-- · 2019-02-17 08:36

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>   
查看更多
登录 后发表回答