canvas - 如何在长列表选择器中设置数据模板的 z 索引

标签 canvas z-index datatemplate longlistselector

我有一个长列表选择器,其中包含我添加到此长列表选择器中的某些图像。 我还更改了该图像的边距,使图像向上或向下等等。 但我想将此图像放在此长列表选择器中的另一图像之前。我尝试过使用 Canvas.Zindex 。 我尝试过将其设置在网格级别、图像级别和 longlistselector 的顶层。() 但它仍然不起作用。有人有一些想法吗?您可以在下面找到我的代码:

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

最佳答案

我只用过WPF,但xaml应该是一样的。

我没有看到您在任何地方引用的 Canvas,所以 Canvas.ZIndex。所以我认为你想要的是将列表的面板设置为 Canvas ,然后设置列表中时间的 Zindex 。

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

关于canvas - 如何在长列表选择器中设置数据模板的 z 索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22151071/

相关文章:

c# - 加快在 WPF 中将对象添加到 Canvas

html - z-index 到背景? CSS

wpf - 如何处理 WPF DataTemplate 中的事件?

html - 防止在 html5 canvas touchmove 事件期间滚动

javascript - 如何平滑我的 JavaScript 动画?

css - 导航下拉菜单上的 IE 7 z-index 问题

html - z-index 不适用于下拉菜单

wpf - 在数据模板中使用样式

c# - 使用 XamlReader 创建的 DataTemplate 无法找到 StaticResources

javascript - 学习 3D 基础知识的资源 (Python/JavaScript)