Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
643 views
in Technique[技术] by (71.8m points)

how can I enable scrollbars on the WPF Datagrid?

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.

What do I need to specify so that the WPF Datagrid has scrollbars?

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>

code-behind:

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;
        }
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...