wpf - 如何在 WPF Datagrid 上启用滚动条?

标签 wpf datagrid scroll

当我从 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放入GridDockPanelContentControl或直接放入Window。垂直方向的 StackPanel 会为其子级提供他们需要的任何垂直空间 - 即使这意味着它会呈现在 View 之外。

关于wpf - 如何在 WPF Datagrid 上启用滚动条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/673516/

相关文章:

c# - 如何在 WPF 中使用 GDI+?

c# - WPF 中 DataGrid 的 CellValueChanged 事件?

jquery - 相对于页面滚动背景

apache-flex - 如何动态改变datagrid行的背景颜色?

c# - 为什么当我从集合中添加或删除项目时,带有 ObservableCollection<T> 的 DataGrid 显然没有刷新?

c# - 如何获得面板上的滚动条位置?窗体 C#

arrays - 在 2D numpy 数组的每个滚动窗口中获得最大值

c# - WPF 文本框接受 INT 但不接受 NULLABLE INT?

c# - 从窗体移植到 WPF

c# - 如何查找在wpf中选中的动态创建的CheckBox