【问题标题】:Order items horizontal in XAML GridView (Win8 / Metro)在 XAML GridView (Win8 / Metro) 中水平排序项目
【发布时间】:2012-12-25 00:00:31
【问题描述】:

如何在 XAML 中对 GridView 的项目进行水平排序? 可悲的是,我没有找到实现这一目标的方法。关键字“方向”不可用。 这是我当前的 GridView:

            <GridView x:Name="TestDataBinding"
                HorizontalContentAlignment="Left"
                VerticalContentAlignment="Top"
                SelectionMode="None"
                ItemsSource="{Binding}"
                ItemTemplateSelector="{StaticResource itemTemplateSelector}"
                Margin="0,60,0,0"
                Width="1100" Height="540"
            />

另一种方式可能是“VariableSizedWrapGrid”。但这不能用于通过“ItemsSource”(和 ItemTemplateSelector)创建项目。

【问题讨论】:

    标签: xaml gridview windows-8 microsoft-metro


    【解决方案1】:

    添加一个 ItemsPanelTemplate 来控制项目的排列方式,例如,

    <GridView.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapGrid Orientation="Horizontal"/>
        </ItemsPanelTemplate>
    </GridView.ItemsPanel>
    

    【讨论】:

      【解决方案2】:

      抱歉,我不得不对您的评论提出异议,即这不能用 VariableSizedWrapGrid 完成。它肯定可以:

      <GridView>
          <GridView.ItemsPanel>
              <ItemsPanelTemplate>
                  <VariableSizedWrapGrid Orientation="Horizontal" />
              </ItemsPanelTemplate>
          </GridView.ItemsPanel>
          <x:String>One</x:String>
          <x:String>Two</x:String>
          <x:String>Three</x:String>
          <x:String>Four</x:String>
      </GridView>
      

      我不得不考虑 VariableSizedWrapGrid 不能用于通过 ItemsSource 创建项目。 大多数当然可以。 WrapGrid 和 VariableSizedWrapGrid 基本相同。 WrapGrid 的重量略轻,因为它不支持列和行跨越。

      【讨论】:

        【解决方案3】:

        只需设置 ItemsWrapGrid 的方向:

        <GridView.ItemsPanel>
            <ItemsPanelTemplate>
                <ItemsWrapGrid Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </GridView.ItemsPanel>
        

        【讨论】:

        • 这样更好,因为这样可以保持拖放的完整性。
        猜你喜欢
        • 2012-09-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-30
        • 1970-01-01
        • 2018-05-28
        相关资源
        最近更新 更多