我有一个DataGrid
,当我将数据加载到其中时,我无法向下滚动
如您所见,底部看不到行 即使当我尝试将突出显示内容放在下面时,我仍然看不到下面的行。
DataGrid
是从列表自动生成的。我尝试设置VerticalScrollBarVisibility
和HorizontalScrollBarVisibility
,但仍然看不到其他数据。
这是我用于数据网格的XAML代码
<StackPanel Orientation="Vertical" Margin="0,0,0,0" Grid.Row="1">
<DataGrid
x:Name="dgvAttendance"
Margin="0,20"
CanUserSortColumns="True"
CanUserAddRows="False" SelectedIndex="0" AlternationCount="2" AutoGenerateColumns="True" SelectionMode="Single" EnableColumnVirtualization="True" IsReadOnly="True" ScrollViewer.CanContentScroll="False" CanUserReorderColumns="False" CanUserResizeColumns="False" HeadersVisibility="All" CanUserResizeRows="False" PreviewMouseWheel="DgvAttendance_PreviewMouseWheel" />
<Button
x:Name="btnExportExcel"
Style="{StaticResource MaterialDesignRaisedDarkButton}"
Width="110"
ToolTip="Resource name: MaterialDesignRaisedLightDarkButton" Margin="15,10" Content="Export File" HorizontalAlignment="Right" Click="BtnExportExcel_Click" />
</StackPanel>
数据网格上还有一个我看不到的按钮
这是我的代码,用于加载dataGrid
public void Main()
{
actuals = NewActual(@"C:\Users\IT\Desktop\Sample\SampleActual.dat");
emps = GetEmp();
var final = (from t1 in actuals
join t2 in emps on t1.ID equals t2.ID
where t1.ID == t2.ID
orderby t2.ID
select new
{
t1.ID,
t2.In,
t1.ActualLog
});
dgvAttendance.ItemsSource = final.ToList();
}
有什么想法为什么我不能向下滚动并看到DataGrid
下面的按钮?谢谢
答案 0 :(得分:1)
根据Polly的建议
我刚刚用ScrollViewer包裹了StackPanel,所以看起来像这样
<ScrollViewer Grid.Row="1">
<StackPanel Orientation="Vertical" Margin="0,0,0,0" >
<DataGrid
x:Name="dgvAttendance"
Margin="0,20"
CanUserSortColumns="True"
CanUserAddRows="False" SelectedIndex="0" AlternationCount="2" AutoGenerateColumns="True" SelectionMode="Single" EnableColumnVirtualization="True" IsReadOnly="True" ScrollViewer.CanContentScroll="False" CanUserReorderColumns="False" CanUserResizeColumns="False" HeadersVisibility="All" CanUserResizeRows="False" PreviewMouseWheel="DgvAttendance_PreviewMouseWheel" >
</DataGrid>
<Button
x:Name="btnExportExcel"
Style="{StaticResource MaterialDesignRaisedDarkButton}"
Width="110"
ToolTip="Resource name: MaterialDesignRaisedLightDarkButton" Margin="15,10" Content="Export File" HorizontalAlignment="Right" Click="BtnExportExcel_Click" />
</StackPanel>
<!-- Stack for Datagrid Ends Here -->
</ScrollViewer>