2015-10-23 56 views
1

我正在使用WrapPanel进行动态内容显示,按行顺序如windows explorer窗口,其工作状态但是当水平和垂直ScrollBar启用WrapPanel时显示内容为单行。这里我们有小于4的内容,它显示完美,否则显示单行。用滚动查看器包装面板

这里是我的xaml代码

<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" Margin="0,10"> 
      <ItemsControl ItemsSource="{Binding Designs}"> 
       <ItemsControl.ItemTemplate> 
        <DataTemplate> 
          <TextBlock HorizontalAlignment="Left" Margin="200,11,0,0" TextWrapping="Wrap" Text="{Binding DsnName}" VerticalAlignment="Top" FontSize="16" FontFamily="Segoe UI Semibold" Foreground="#FF878787"/> 
          <Image Source="{Binding Image,FallbackValue={StaticResource Lost},TargetNullValue={StaticResource Lost},Mode=TwoWay}" Stretch="Fill" RenderOptions.BitmapScalingMode="HighQuality" HorizontalAlignment="Left" Margin="10,10,0,10" Width="174"/> 
          <CheckBox HorizontalAlignment="Right" Margin="0,14,12,0" VerticalAlignment="Top" Width="16"/> 
         </Grid> 
        </DataTemplate> 
       </ItemsControl.ItemTemplate> 
       <ItemsControl.ItemsPanel> 
        <ItemsPanelTemplate> 
        <WrapPanel Orientation="Horizontal"/> 
        </ItemsPanelTemplate> 
       </ItemsControl.ItemsPanel> 
     </ItemsControl> 
     </ScrollViewer> 

怎样才能解决这个问题

+0

如果你使用'ScrollViewer',内容会自动被赋予尽可能多的空间,因为它需要。因此,如果WrapPanel的宽度没有限制,则不需要换行。如果要包装,则必须禁用水平滚动或在内容上设置最大宽度。 – vesan

回答

1

WrapPanel的设置高度或禁用滚动