【发布时间】:2014-04-20 03:04:54
【问题描述】:
我是 WPF/Xaml 的新手,并搜索了我面临的这个问题,但发现它很难。请求一些帮助。
我需要在面板/列表视图中显示用户控件(DATABOUND)(水平),以便它们在满足列表视图/面板的宽度时换行,并自动显示垂直滚动条(如图所示)。 到目前为止,我有这个代码。
<ListView Grid.Row="3"
ItemsSource="{Binding Controls}"
VerticalAlignment="Bottom" Background="{x:Null}" BorderBrush="{x:Null}"
>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,10"></StackPanel>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="VerticalContentAlignment" Value="Bottom"/>
<Setter Property="Focusable" Value="False" />
</Style>
</ListView.ItemContainerStyle>
<!--<ListView.ItemTemplate>
<DataTemplate>
<ContentControl Content="{Binding}" VerticalContentAlignment="Bottom"/>
</DataTemplate>
</ListView.ItemTemplate>-->
</ListView>
我什至尝试过下面的代码。是的,它会换行,但没有出现滚动条!
<ItemsControl Grid.Row="3"
Width="100" Height="200"
ItemsSource="{Binding Controls}"
VerticalAlignment="Bottom" Background="{x:Null}" BorderBrush="{x:Null}"
>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" Margin="0,0,0,10"></WrapPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
注意:我可以接受任何使这种情况发生的控件。不一定是列表视图。
【问题讨论】:
标签: wpf mvvm wpf-controls wpfdatagrid wrappanel