如何在Wpf中的Datagrid中显示水平滚动条

问题描述:



任何人都可以帮助我,你的答案非常受欢迎。

问题:只有点击datagrid的右上角才会显示水平滚动条。但是想要一直显示它而不点击任何地方。



以下是我的代码



Hi,
Can any one help me, your answers is heartly appreciated.
Problem: Horizontal scroll bar only display if I click on upper right corner of datagrid. But want to display it all the time without clicking anywhere.

Following are my code

<Window>
  <Grid>
    <GroupBox>
      <StackPanel>
         <DataGrid HorizontalAlignment="Center" AutoGenerateColumns="False" 

                              ScrollViewer.CanContentScroll="True"         

                              ScrollViewer.IsDeferredScrollingEnabled="True" 

                              ScrollViewer.HorizontalScrollBarVisibility="Visible" >
             <DataGrid.Columns>
                  //Some Columns here
             </DataGrid.Columns>
         </DataGrid>
      </StackPanel>
    </GroupBox>
  </Grid>
</Window>

尝试:将DataGrid放入ScrollViewer标签内,然后设置高度,宽度等。代码示例如下所示。

Try: Put DataGrid inside ScrollViewer tag then set Height, Width etc. Code sample as shown below.
<Grid>
       <GroupBox>
           <StackPanel Orientation="Horizontal" >
               <ScrollViewer  Width="500" ScrollViewer.VerticalScrollBarVisibility="Auto" Foreground="Red">
                   <DataGrid  HorizontalAlignment="Center" AutoGenerateColumns="False" >
                       <DataGrid.Columns>
                       </DataGrid.Columns>
                   </DataGrid>
               </ScrollViewer>
           </StackPanel>
       </GroupBox>
   </Grid>





如有问题请告诉我们。



In case of issue let us know.