如何在 WPF Datagrid 上启用滚动条? [英] how can I enable scrollbars on the WPF Datagrid?
问题描述
当我从 运行以下 Northwind WPF Toolkit Datagrid 代码时这篇文章,我得到了一个数据网格,但是没有滚动条,因此用户只能看到数据网格的一部分.我使用的是 2009 年 3 月的最新版本.
When I run the following Northwind WPF Toolkit Datagrid code from this article, I get a datagrid, but there are no scrollbars and hence the user can only see part of the datagrid. I am using the newest version March 2009.
我需要指定什么才能使 WPF Datagrid 具有滚动条?
我尝试将数据网格放在 ScrollViewer 中,但这没有帮助.
I tried putting the datagrid in a ScrollViewer but that didn't help.
XAML:
<Window x:Class="TestDataGrid566.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
Title="Window1" Height="600" Width="800">
<StackPanel>
<toolkit:DataGrid x:Name="TheDataGrid" AutoGenerateColumns="True"/>
</StackPanel>
</Window>
代码隐藏:
using System.Linq;
using System.Windows;
using TestDataGrid566.Model;
namespace TestDataGrid566
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
NorthwindDataContext db = new NorthwindDataContext();
var customers = from c in db.Customers
select c;
TheDataGrid.ItemsSource = customers;
}
}
}
推荐答案
将 DataGrid
放入 Grid
、DockPanel
、ContentControl
或直接在 Window
中.垂直方向的 StackPanel
将为其子项提供他们要求的任何垂直空间 - 即使这意味着它被呈现在视野之外.
Put the DataGrid
in a Grid
, DockPanel
, ContentControl
or directly in the Window
. A vertically-oriented StackPanel
will give its children whatever vertical space they ask for - even if that means it is rendered out of view.
这篇关于如何在 WPF Datagrid 上启用滚动条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!