简体   繁体   中英

ScrollBar is not showing in WPF ListView which is inside nested User and Content Controls

Please help me in this issue of scroll bar visibility in WPF listview. I have a listview inside a Content Control. This Content Control is inside a User Control. This User Control is inside a TabItem.

The listview has around 12 columns to display, which exceeds the window width. I tried so many ways to show the horizontal scroll bar in the listview.

Below shown is the XAML of the Outer UserControl [width is not set for this outer 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>

Now below is the usrAControl XAML details

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

I tried with lot of combination. I initially put a scrollviewer control inside the tabitem and placed usrAControl inside it. But it did not work.

But I want the listview should show its both scroll bars. Is any way to do it.?

Without seeing more code, my guess would be that the MinSize="640" is your problem: the ListView gets enough space from its container so it doesn't show the scroll, but the container gets clipped.

And you should get rid of the ListView Width binding, it's completely redundant.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM