2009-03-23 4 views
47

, 나는 데이터 그리드를 얻을 수 있지만,이 에는 스크롤바가 없습니다 따라서 사용자가 데이터 그리드의 일부를 볼 수만 있습니다. 2009 년 3 월 최신 버전을 사용하고 있습니다.WPF Datagrid에서 스크롤 막대를 활성화하려면 어떻게해야합니까? 내가 <a href="http://www.codeproject.com/KB/WPF/WPFDataGrid.aspx" rel="noreferrer">this article</a>에서 다음 <strong>Northwind를 WPF 툴킷에서 Datagrid</strong> 코드를 실행하면

WPF Datagrid에 스크롤 막대가 있도록 지정해야하는 항목은 무엇입니까?

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; 
     } 
    } 
} 
+0

[WPF Datagrid - 스크롤 막대를 표시하지 않음]의 가능한 복제본 (https://stackoverflow.com/questions/24015890/wpf-datagrid-not-showing-any-scrollbar) –

답변

79

Window에 직접 Grid, DockPanel, ContentControlDataGrid을 넣거나. 수직으로 방향을 바꾼 StackPanel은 아이들에게 그들이 요구하는 수직 공간이 무엇이든 상관없이 아이들에게 줄 것이다. 와

+1

추가하려면 'HeaderedContentControl' 내부적으로'StackPanel'으로 구현되어'DataControl'과 모순되는 방식으로'DataGrid'를 동작하게합니다. – user7116

+2

내 XAML 맨 위에 보이지 않는 StackPanel 태그를 마침내 발견 할 때까지이 조언이 몇 시간 동안 쓰레기라고 생각했습니다. 감사! – Ted

+1

또한 세로 지향 스택 패널을 사용하면 가상화를 방해하고 응용 프로그램 성능에 영향을 미칩니다. – kiran

35

WPF4

<DataGrid AutoGenerateColumns="True" Grid.Column="0" Grid.Row="0" 
     ScrollViewer.CanContentScroll="True" 
     ScrollViewer.VerticalScrollBarVisibility="Auto" 
     ScrollViewer.HorizontalScrollBarVisibility="Auto"> 
</DataGrid> 

: <ColumnDefinition Width="350" /> & <RowDefinition Height="300" /> 잘 작동합니다.

스크롤 막대가 <ColumnDefinition Width="Auto" /> & <RowDefinition Height="300" />과 함께 표시되지 않습니다. 이것은 외부 <Grid> 중첩되는 경우 <ColumnDefinition Width="*" /> & <RowDefinition Height="300" /> :

또한 미세 작동한다. "자동"으로 설정 부모 컨테이너의 RowDefinition 높이의도 스크롤

또는 당신이 높이를 설정할 수 있습니다 "*"에 대한 스토퍼 경우

+0

내 intellisense는 * DataGrid에 * ScrollViewer *가 없다고 알려줍니다. –

+1

@Konrad Viltersten'ScrollViewer'는 첨부 된 속성입니다. – xmedeko

+0

감사합니다. 도움이됩니다! – Sunny656

13

내 경우에 발생한다.

5

DataGrid에 MaxHeight 및 VerticalScrollBarVisibility = "Auto"를 추가하면 내 문제가 해결되었습니다.

1

열과 행에 대해 정의 된 높이와 너비가있는 격자를 추가하십시오. 그런 다음 ScrollViewer를 추가하고 내부에 dataGrid를 추가합니다.

관련 문제