ListViewItem中Expander未显示的内容

问题描述 投票:1回答:1

我有以下设置,你可以在这里看到

<ListView>
       <ListViewItem x:Name="ItemHome" Height="60">
          <ListViewItem.Content>
              <StackPanel Orientation="Horizontal">
                   <materialDesign:PackIcon
                           Width="25"
                           Height="25"
                           Margin="10"
                           VerticalAlignment="Center"
                           Kind="Database" />
                   <Expander
                           VerticalAlignment="Center"
                           Background="{x:Null}"
                           FontFamily="20"
                           Header="TEST">
                    <Expander.Content>
                           <StackPanel Background="Green" Orientation="Vertical">
                                         <ListViewItem Height="60">
                                            <StackPanel Orientation="Horizontal">
                                               <materialDesign:PackIcon
                                                  Width="25"
                                                  Height="25"
                                                  Margin="10"
                                                  VerticalAlignment="Center"
                                                  Kind="Octagon" />
                                               <TextBlock
                                                  Margin="20,10"
                                                  VerticalAlignment="Center"
                                                  FontFamily="20"
                                                  Text="TEST" />
                                            </StackPanel>
                                         </ListViewItem>
                                         <ListViewItem Height="60">
                                            <StackPanel Orientation="Horizontal">
                                               <materialDesign:PackIcon
                                                  Width="25"
                                                  Height="25"
                                                  Margin="10"
                                                  VerticalAlignment="Center"
                                                  Kind="Needle" />
                                               <TextBlock
                                                  Margin="20,10"
                                                  VerticalAlignment="Center"
                                                  FontFamily="20"
                                                  Text="TEST" />
                                            </StackPanel>
                                         </ListViewItem>
                                      </StackPanel>
                                   </Expander.Content>
                                </Expander>
                             </StackPanel>
                </ListViewItem.Content>
          </ListViewItem>
</ListView>

问题是我相信我搞砸了代码,因为当我点击展开按钮时,没有任何显示。试图给扩展器内容一个高度/宽度,但没有运气。扩展器按钮显示他已扩展,但仅此而已。有任何想法吗?谢谢

c# wpf xaml listviewitem expander
1个回答
1
投票

问题是你正在设置ListViewItem的高度属性:enter image description here

这会导致项目永远不会增长。删除此任务并进行一些调整,你会得到一些有用的东西(注意:我用我的ctl替换materialDesign:PackIcon:SymbolIcon,任何人都可以使用任何图标或图像):

    <ListView>
        <ListViewItem x:Name="ItemHome">                
            <StackPanel Orientation="Horizontal" >                        
                    <ctl:SymbolIcon Symbol="Calendar" Width="25" Height="25" Margin="10" VerticalAlignment="Top"/>
                    <Expander VerticalAlignment="Top" Background="{x:Null}" FontFamily="20" Header="TEST" Margin="0,10,10,10">
                            <StackPanel Orientation="Vertical">
                                <ListViewItem Height="60" Background="ForestGreen">
                                    <StackPanel Orientation="Horizontal">
                                        <ctl:SymbolIcon Width="25" Height="25" Margin="10" VerticalAlignment="Center" Symbol="Send" 
                                                        Foreground="White"/>
                                        <TextBlock Margin="20,10" VerticalAlignment="Center" FontFamily="20" Text="TEST" 
                                                   Foreground="White"/>
                                    </StackPanel>
                                </ListViewItem>
                                <ListViewItem Height="60" Margin="0,1,0,0" Background="ForestGreen">
                                    <StackPanel Orientation="Horizontal">
                                        <ctl:SymbolIcon Width="25" Height="25" Margin="10" VerticalAlignment="Center" Symbol="Accept" 
                                                        Foreground="White"/>
                                        <TextBlock Margin="20,10" VerticalAlignment="Center" FontFamily="20" Text="TEST" 
                                                   Foreground="White"/>
                                    </StackPanel>
                                </ListViewItem>
                            </StackPanel>
                    </Expander>
                </StackPanel>                
        </ListViewItem>
    </ListView>

结果:enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.