【问题标题】:how to locate an item in a specific row and column in a verticaly-wrapped VariableSizedWrapGrid?如何在垂直包装的 VariableSizedWrapGrid 的特定行和列中定位项目?
【发布时间】:2013-03-28 11:49:57
【问题描述】:

我想在 VariableSizedWrapGrid 的自动生成的垂直环绕列表中的特定行和列中定位一个项目。 我的视图模型公开了一个集合,我希望第一个项目位于第一行和第一列(我的意思是 0,0 - 这不是问题)。另外我希望集合中的第二项位于第二列和第一行 (0,1) 中,并且我希望第三项位于第二项下方的 (1,1) 中。 . 其余项目位于剩余的可用空间中...... 我发现这是一个问题,因为我不知道这个垂直环绕可调网格中的行数是多少......

你建议我做什么?

【问题讨论】:

  • 您应该正确标记您的问题以避免混淆。由于 Wpf 没有 VariableSizedWrapGrid 这个问题应该用 xaml-rt 标记。因此 UniformGrid 存在于 wpf 中,但不存在于 winrt 中。

标签: wpf windows xaml gridview windows-8


【解决方案1】:

使用UniformGrid 和ItemsControl 应该可以为您提供所需的结果。例如,如果List<string> 是DataContext:

<ItemsControl ItemsSource="{Binding}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <-- set the desired number of columns and omit the number of rows -->
            <UniformGrid Columns="2" />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Border Margin="2"
                    BorderBrush="Tomato"
                    BorderThickness="1">
                <Grid>
                    <TextBlock Text="{Binding}" />
                </Grid>
            </Border>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-21
    • 1970-01-01
    • 2015-11-16
    • 1970-01-01
    • 2021-10-28
    • 1970-01-01
    相关资源
    最近更新 更多