У меня есть TreeView, содержащий родителя и пару детей. Дети, в свою очередь, состоят из WrapPanel с собственными детьми («Один», «Два», «Три» и т. Д.). Как я могу заставить эти последние элементы обернуть, когда родительское окно недостаточно велико, чтобы разместить их?Как обернуть WrapPanel детей в TreeView?
Вот мой код:
<TreeView ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<TreeViewItem Header="Parent" IsExpanded="True" >
<ItemsControl>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.Items>
<TextBlock Text="One" />
<TextBlock Text="Two" />
<TextBlock Text="Three" />
<TextBlock Text="Four" />
<TextBlock Text="Five" />
<TextBlock Text="Six" />
<TextBlock Text="Seven" />
<TextBlock Text="Eight" />
<TextBlock Text="Nine" />
<TextBlock Text="Ten" />
</ItemsControl.Items>
</ItemsControl>
<ItemsControl>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.Items>
<TextBlock Text="One" />
<TextBlock Text="Two" />
<TextBlock Text="Three" />
<TextBlock Text="Four" />
<TextBlock Text="Five" />
<TextBlock Text="Six" />
<TextBlock Text="Seven" />
<TextBlock Text="Eight" />
<TextBlock Text="Nine" />
<TextBlock Text="Ten" />
</ItemsControl.Items>
</ItemsControl>
</TreeViewItem>
</TreeView>
И вот что он в настоящее время производит:
Установив ширину в ItemsControl/WrapPanel, вы можете добиться обертывания –