2

ツリービューの問題を解決しようとしています。ツリービューノードのwrappanel内でアイテム(UserControls)を注文したいと思います。

-Group
 |---------------------------------------------|
 |Item Item Item Item Item Item Item Item Item |
 |---------------------------------------------|
+Group
+Group

ウィンドウ幅(およびツリービュー幅に沿った)が抑制され、アイテムが1行に収まらない場合は、次の行に並べ替える必要があります。

-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>
4

1 に答える 1

1

ItemsPanelforを設定するTreeViewItems必要があります。

<TreeView.ItemContainerStyle>
    <Style TargetType="TreeViewItem">
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <WrapPanel />
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</TreeView.ItemContainerStyle>

また、折り返しを可能にするために水平スクロールをオフにします。

<TreeView ScrollViewer.HorizontalScrollBarVisibility="Disabled" ...>
于 2012-02-12T12:13:13.437 に答える