带wrappanel的Treeview - 灵活分组
我正在尝试解决树视图的问题。 我想在树视图节点的包装面板内订购项目(用户控件)。
-Group
|---------------------------------------------|
|Item Item Item Item Item Item Item Item Item |
|---------------------------------------------|
+Group
+Group
如果窗口宽度(以及沿树视图宽度)被抑制并且项目不适合一行,则应将这些项目排序到下一行。
-Group
|-------------------------|
|Item Item Item Item Item |
|Item Item Item Item |
|-------------------------|
+Group
+Group
我已经完成了上面的示例,它不会将项目放在下一行。这可以在没有 Treeview 的情况下工作,但在 Treeview-node 内部缺少一些东西。
<DataTemplate x:Key="GroupTemplateFrontPage">
<Border BorderBrush="AliceBlue" BorderThickness="1" CornerRadius="10"
Background="{StaticResource TreeViewItemBackground}" >
<Expander HeaderTemplate="{DynamicResource HeaderTemplate}"
Header="{Binding}" IsTabStop="False" HorizontalAlignment="Left"
IsEnabled="True" ExpandDirection="Down" IsExpanded="True">
<Grid Margin="5,5,5,5">
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<ListBox Margin="10,39,0,0" VerticalAlignment="Top" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemsSource="{Binding Modems}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel
HorizontalAlignment="Stretch"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Disabled"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Controls:UserControlItem Margin="4" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Expander>
</Border>
</DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock Text="Treeview" />
<TreeView Name="_treeView" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
Margin="0,0,0,0"
ItemsSource="{Binding}"
ItemTemplate="{StaticResource GroupTemplateFrontPage}" />
</StackPanel>
I'n trying to resolve problem with treeview.
I would like to get items (UserControls) ordered inside wrappanel, in treeview node.
-Group
|---------------------------------------------|
|Item Item Item Item Item Item Item Item Item |
|---------------------------------------------|
+Group
+Group
If window width (and along treeview width) suppress and items wont fit to one line, those should be ordered to next line.
-Group
|-------------------------|
|Item Item Item Item Item |
|Item Item Item Item |
|-------------------------|
+Group
+Group
I have done above example which won't put items on next row. This is working without Treeview, but inside treeview-node something is missing..
<DataTemplate x:Key="GroupTemplateFrontPage">
<Border BorderBrush="AliceBlue" BorderThickness="1" CornerRadius="10"
Background="{StaticResource TreeViewItemBackground}" >
<Expander HeaderTemplate="{DynamicResource HeaderTemplate}"
Header="{Binding}" IsTabStop="False" HorizontalAlignment="Left"
IsEnabled="True" ExpandDirection="Down" IsExpanded="True">
<Grid Margin="5,5,5,5">
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<ListBox Margin="10,39,0,0" VerticalAlignment="Top" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemsSource="{Binding Modems}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel
HorizontalAlignment="Stretch"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Disabled"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Controls:UserControlItem Margin="4" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Expander>
</Border>
</DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock Text="Treeview" />
<TreeView Name="_treeView" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
Margin="0,0,0,0"
ItemsSource="{Binding}"
ItemTemplate="{StaticResource GroupTemplateFrontPage}" />
</StackPanel>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设置
TreeViewItems
的ItemsPanel
应该这样做:同时关闭水平滚动以允许换行:
Setting the
ItemsPanel
forTreeViewItems
should do:Also turn off horizontal scrolling to allow for wrapping: