【发布时间】:2010-10-28 19:54:22
【问题描述】:
我正在制作一个简单的 LOB 应用程序,它从 XML 文件加载数据并将其显示在带有几个按钮的列表中以供编辑。
在我的第一次尝试中,一切都很好,只是列表在一个长列中向下滚动。我希望将数据包装起来,以便在窗口底部开始第二列,依此类推——如果您调整窗口大小,数据应该相应地调整大小。
首先,我只是将 ListBox 放在 ScrollViewer 中。这没有任何区别。
然后,我在 ItemTemplate 中添加了 WrapPanel。在这一点上,我得到了一个水平的长行,但它从来没有换到第二行,尽管我设置了 ScrollViewer.HorizontalScrollbar=disabled。
我在各种博客和论坛上搜索了网络,但看不出建议和我的代码(包括在下面)之间的区别。任何提示将不胜感激。
<Window x:Class="MyApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="My App" Height="300" Width="400"
FocusManager.FocusedElement="{Binding ElementName=eventsList}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ScrollViewer Grid.Row="0" Grid.Column="0" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<ListBox Name="eventsList">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</ScrollViewer>
<StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Center" Visibility="Collapsed">
<Button Name="action1Button" />
<Button Name="action2Button" />
<Button Name="action3Button" />
</StackPanel>
</Grid>
</Window>
【问题讨论】:
标签: wpf data-binding xaml listbox