如何在WPF Datagrid上启用滚动条? [英] how can I enable scrollbars on the WPF Datagrid?
问题描述
当我从运行以下 Northwind WPF Toolkit Datagrid 代码时这篇文章,我得到一个datagrid,但是有 no scrollbars ,因此用户只能看到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: / p>
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
放在网格
中, DockPanel
, ContentControl
或直接在窗口
中。一个垂直导向的 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屋!