Using A WrapPanel in a TreeView

前端 未结 3 1166
自闭症患者
自闭症患者 2021-01-29 10:35

I want to display data with level of detail, so i use a TreeView, but each detail is quite short, so i would like to use a WrapPanel (horizontal) to have many details per line.<

相关标签:
3条回答
  • 2021-01-29 11:01

    Try

    1. Disable the scroll bars
    2. Widen the WrapPanel and see the visual impact, is it effected?
    3. Make a color border/background to track the actual size of the WrapPanel

    These will help you trace the problem

    0 讨论(0)
  • 2021-01-29 11:06

    EDIT : i finally got this to work with a 'simpler' solution. Still it seems that we have to define the WrapPanel's Width, which make the solution less generic. (Maybe a binding of the width (but which ?) would solve this)

    Here's the solution i came to : just defining, in a style, the ItemsPanel used in a TreeViewItem :

    <Style TargetType="TreeViewItem">
       <Setter Property="ItemsPanel">
           <Setter.Value>
                  <ItemsPanelTemplate>
                    <WrapPanel  Orientation="Horizontal"      
                                Width="520"
                                HorizontalAlignment="Stretch" 
                                Margin="0" 
                                ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                                IsItemsHost="True"  
                        />
                  </ItemsPanelTemplate>
           </Setter.Value>
       </Setter>
    </Style>
    
    0 讨论(0)
  • 2021-01-29 11:07

    You must set

    ScrollViewer.HorizontalScrollBarVisibility="Disabled"
    

    to your

    <TreeView/>
    

    not for

    <WrapPanel/>
    

    example:

    <TreeView x:Name="fieldTreeView" Grid.Row="1" Margin="5,0,5,0" Background="Beige"         
              ItemsSource="{Binding Source={StaticResource bla}}"
              ScrollViewer.HorizontalScrollBarVisibility="Disabled">
            <TreeView.Resources>                
                <DataTemplate DataType="{x:Type Model:bla}">
                    <StackPanel Orientation="Vertical">
                        <Label Content="{Binding Name}"/>
                        <TextBox Text=""/>
                    </StackPanel>        
                </DataTemplate>                
            </TreeView.Resources>
            <TreeView.ItemsPanel>
                <ItemsPanelTemplate>                    
                    <WrapPanel Orientation="Horizontal"/>                    
                </ItemsPanelTemplate>
            </TreeView.ItemsPanel>
        </TreeView>
    

    This solution works for me.

    0 讨论(0)
提交回复
热议问题