gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 05:43:14 25 4
gpt4 key购买 nike

当我从 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com