2012-05-24 5 views
1

WPF에서 작업 중입니다. DataGrid가 포함 된 컨트롤을 디자인 중이며 지금까지 모든 것이 잘 진행됩니다.DataGrid에 데이터가없는 경우 행이 누락 됨

하지만 이상한 일이 있습니다. 데이터 격자에 하나 이상의 행을 표시하면 DataGrid는 정상적으로 새 행을 추가하는 데 사용 된 빈 행을 마지막에 표시하지만 데이터 격자에 행이없는 경우 빈 행이 표시되지 않습니다.

그래서 데이터의 여부에 관계없이 빈 행의 끝에 항상 DataGrid가 있어야합니다.

속성은 CanUserAddRowsIsReadOnly으로 시도했지만 이전에 말했듯이 하나 이상의 행이있을 때만 작동합니다.

아무에게도이를 수행하는 방법을 알고 있습니까?

은 사전에 감사합니다.

답변

1

빈 행을 의미합니까?

public class Data 
{ 
    public Data(string value) { MyProperty = value; } 
    public Data() { } // Must have default constructor 
    public String MyProperty { get; set; } 
} 

/// <summary> 
/// Interaction logic for MainWindow.xaml 
/// </summary> 
public partial class MainWindow : Window 
{   
    List<Data> _items = new List<Data>(); 
    public List<Data> Items 
    { 
     get { return _items; } 
    } 

    public MainWindow() 
    { 
     InitializeComponent(); 
    } 
뒤에 (바인딩도 ItemsSource가 데이터가없는)

<Window x:Class="Demo.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="MainWindow" Height="350" Width="525" 
    DataContext="{Binding RelativeSource={RelativeSource Self}}" 
    > 
<Grid> 
    <DataGrid ItemsSource="{Binding Items}"> 
     <!--Must define columns if you need columns before bound collection has data--> 
     <DataGrid.Columns> 
      <DataGridTextColumn Header="Property" Binding="{Binding Path=MyProperty}"> </DataGridTextColumn> 
     </DataGrid.Columns> 
    </DataGrid> 
</Grid> 
</Window> 

코드를 XAML을 빈 행을 표시 않습니다 wpf datagrid blank row missing

이 기본 셋업에 대한 답변에서보세요

+0

사실 나는 그 게시물을 읽었지 만 나에게 유용하지는 않았다. 나는 여전히 이상한 문제가있다. – Dante

+0

@ 단테 바운드 데이터 그릿은 무엇인가? 문제를 재현 할 수있는 충분한 코드를 게시 할 수 있습니까? – grantnz

+0

지금 DataTable에서 데이터를 가져오고 있습니다.이 작업은 다음과 같습니다.'MyDataGrid.ItemsSource = myDataTable.DefaultView' – Dante

관련 문제