【问题标题】:How to use multiple GridView ItemTemplate's (WinRT/XAML)如何使用多个 GridView ItemTemplate (WinRT/XAML)
【发布时间】:2012-09-26 19:34:12
【问题描述】:

我创建了一个 GridView 界面,其中包含不同大小的图块(如 Windows 开始屏幕)。如何在每个图块上以不同的方式定位控件?我的代码目前如下所示:

                <DataTemplate>
                <Grid Height="500" Width="1000">
                    <Grid.Background>
                        <SolidColorBrush Color="{Binding TileColor}"/>
                    </Grid.Background>
                    <StackPanel VerticalAlignment="Top">
                        <TextBlock Foreground="{Binding TextColor}" FontSize="25" TextWrapping="Wrap" Text="{Binding Title}" Margin="10,10,720,0"/>
                    </StackPanel>
                    <StackPanel VerticalAlignment="Bottom">
                        <TextBlock Foreground="{Binding TextColor}" FontSize="20" TextWrapping="Wrap" Text="{Binding Subtitle}" Height="334" Margin="10,0,336,15" RenderTransformOrigin="0.497,0.59"/>
                    </StackPanel>
                </Grid>
            </DataTemplate>

但由于瓷砖高度不同,它的布局不正确。有没有办法可以定义多个 ItemTemplates?

谢谢

【问题讨论】:

    标签: c# xaml windows-runtime


    【解决方案1】:

    您可以创建多个数据模板,然后您需要使用 DataTemplateSelector 将它们映射到您的图块。我想这篇文章会完美回答你的问题!

    http://visualstudiomagazine.com/articles/2012/08/06/multiple-item-templates-in-windows-phone.aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多