当我从 this article 运行以下 Northwind WPF Toolkit Datagrid 代码时,我得到一个数据网格,但是没有滚动条,因此用户只能看到数据网格的一部分。我使用的是 2009 年 3 月的最新版本。
我需要指定什么才能使 WPF Datagrid 具有滚动条?
我尝试将数据网格放入 ScrollViewer 中,但这没有帮助。
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 会为其子级提供他们需要的任何垂直空间 - 即使这意味着它会呈现在 View 之外。
关于wpf - 如何在 WPF Datagrid 上启用滚动条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/673516/