【问题标题】:ScrollBar is not showing in WPF ListView which is inside nested User and Content ControlsScrollBar 未显示在嵌套的用户和内容控件内的 WPF ListView 中
【发布时间】:2013-10-06 13:10:34
【问题描述】:

请帮助我解决 WPF 列表视图中滚动条可见性的问题。 我在内容控件中有一个列表视图。 此内容控件位于用户控件内。 此用户控件位于 TabItem 内。

列表视图有大约 12 列要显示,这超出了窗口宽度。 我尝试了很多方法来在列表视图中显示水平滚动条。

下面显示的是外部用户控件的 XAML [未为此外部 usrCrtl 设置宽度]

       <Grid>
            <Grid.RowDefinitions>
               <RowDefinition Height="Auto" />
               <RowDefinition Height="*" />   // Here I have a custom content control
               <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <MyCustomContentControl Grid.Row=1  VerticalAlignment="Stretch"......>
               <TabControl>
                   <TabItem Header="One" Name="Tab1">
                        <my:usrAControl />   // I have listview inside this userctrl                       
                    </TabItem>
               </TabControl>
               <TabControl Header="Two" Name="Tab2" />
            </MyCustomContentControl>
       </Grid>

下面是 usrAControl XAML 详细信息

       <UserControl x:Class="MyProject.MyModule.usrAControl"
            MinWidth="640">
          // Again inside another custom user control as its child.
             <usrBControl>
                  <Grid>
                     <Grid.RowDefinitions>
                         <RowDefinition Height="30" /> // here another headers
                         <RowDefinition Height="*" />  // here my listview placed
                     </Grid.RowDefinitions>  

                     <ListView ScrollViewer.HorizontalScrollBarVisibility="Auto" Grid.Row="1"
                               Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=Width}">

                      // Around 12 columns which exceeds window width

                     </ListView>  
                  </Grid>
             </usrBControl>             
       </usrAControl>

我尝试了很多组合。 我最初在 tabitem 中放置了一个滚动查看器控件,并将 usrAControl 放置在其中。 但它没有用。

但我希望列表视图应该显示它的两个滚动条。有什么办法吗?

【问题讨论】:

    标签: c# wpf listview


    【解决方案1】:

    没有看到更多代码,我猜MinSize="640" 是你的问题:ListView 从其容器中获得足够的空间,因此它不显示滚动,但容器被剪裁了。

    而且你应该去掉 ListView Width 绑定,它完全是多余的。

    【讨论】:

    • 您好 Eli Arbel,我再次尝试删除 MinWidth 和 ListView 宽度绑定,但仍然没有用。还有什么办法???
    • 你必须添加更多代码。 usrBControlMyCustomContentControl 中有什么内容?代码按原样工作。
    • 嗨,Eli,我通过将滚动查看器作为列表视图的父级来修复它。所以现在两个滚动条都是可见的。感谢您的时间、建议和帮助
    • 这是一个糟糕的解决方案。您会遇到滚动、虚拟化等问题。尝试以其他方式修复它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-28
    • 1970-01-01
    • 2012-04-25
    • 1970-01-01
    相关资源
    最近更新 更多