2017-08-10 36 views
0

以下是我的xaml代码,它定义了ListView。输出是系列产品。但问题在于产品接连不断。自适应列表视图帮助(Windows通用应用程序)

Image of universal output

我想要的输出垂直对齐一个接一个。

<ListView x:Name="list" Margin="0,0,0,0" SelectionChanged="list_SelectionChanged" VerticalAlignment="Top"> 
    <ListView.Resources> 
     <DataTemplate x:Key="myCell"> 
      <Border BorderBrush="Gray" BorderThickness="0,0,0,0" > 
       <Grid Margin="0" x:Name="tryadpative" > 
        <Grid.RowDefinitions> 
         <RowDefinition Height="8*" /> 
         <RowDefinition Height="1*" /> 
         <RowDefinition Height="1*" /> 
        </Grid.RowDefinitions> 

        <Image x:Name="prodimg" Width="auto" Source="{Binding prodimg}" Grid.Row="0"></Image> 
        <TextBlock x:Name="productcode" TextWrapping="Wrap" Text="{Binding productcode}" HorizontalAlignment="Center" Width="auto" FontSize="12" Grid.Row="1" Foreground="Gray"/> 
        <TextBlock x:Name="productname" FontSize="14" HorizontalAlignment="Center" VerticalAlignment="Bottom" Foreground="Gray" Grid.Row="0" Text="{Binding productname}" /> 
        <TextBlock x:Name="productmindec" TextWrapping="Wrap" HorizontalAlignment="Center" Text="{Binding productmindec}" Width="auto" FontSize="14" Grid.Row="2" Foreground="Gray"/> 

        <!--<Image x:Name="prodimg" Width="auto" Source="{Binding prodimg}" Grid.Row="0"></Image> 
        <TextBlock x:Name="productcode" TextWrapping="Wrap" Text="{Binding productcode}" Width="auto" FontSize="12" Foreground="Gray"/> 
        <TextBlock x:Name="productname" FontSize="14" Foreground="Gray" Text="{Binding productname}" /> 
        <TextBlock x:Name="productmindec" TextWrapping="Wrap" Text="{Binding productmindec}" Width="auto" FontSize="14" Foreground="Gray"/>-->                     

       </Grid> 
      </Border> 
     </DataTemplate> 
    </ListView.Resources> 

    <!--<ListView.ItemContainerStyle> 
     <Style TargetType="ListViewItem"> 
      <Setter Property="HorizontalContentAlignment" Value="Stretch" /> 
     </Style> 
    </ListView.ItemContainerStyle>--> 

    <ListView.ItemTemplate> 
     <StaticResource ResourceKey="myCell"/> 
    </ListView.ItemTemplate> 

</ListView> 

回答

0

ItemsStackPanel可以使用仅作为一次显示多个项目一个ItemsControl的ItemsPanel。它不能用于一次只显示一个项目的ItemsControl,如ComboBox或FlipView。 ItemsStackPanel是ListView的默认ItemsPanel。

默认情况下,ItemsStackPanel从上到下垂直堆叠项目。您可以将“方向”属性设置为“水平”以从左到右堆叠项目。

有关更多信息,请参见ItemsStackPanel

我们应该能够将Horizontal设置为ItemsStackPanelOrientation

例如:

<ListView.ItemsPanel> 
    <ItemsPanelTemplate> 
     <ItemsStackPanel Orientation="Horizontal" > 
     </ItemsStackPanel> 
    </ItemsPanelTemplate> 
</ListView.ItemsPanel> 

顺便说一句,如果你想在滚动水平ListView的,你应该能够设置VisibleScrollViewer.HorizontalScrollBarVisibilityEnabledScrollViewer.HorizontalScrollModeListView

例如:

<ListView x:Name="list" 
      Margin="0,0,0,0" 
      SelectionChanged="list_SelectionChanged" 
      VerticalAlignment="Top" 
      SelectionMode="Single" 
      ScrollViewer.HorizontalScrollBarVisibility="Visible" 
      ScrollViewer.HorizontalScrollMode="Enabled"> 
</ListView> 
相关问题