2012-12-15 4 views
1

MVVM 기반의 WPF 프로젝트가 있습니다. 내보기에 나는 다음 목록 상자를단 하나의 레코드를 보여주는 목록 상자에 데이터 세트 바인딩

<ListBox BorderBrush="#6797c8" BorderThickness="2" 
    ItemsSource="{Binding Path=CategoriesDS}" 
    DisplayMemberPath="MainCategories/Category"/> 

을 그리고 이것은 뷰 모델에서 내 코드입니다 :

private DataSet categoriesDS; 

public DataSet CategoriesDS 
{ 
    get 
    { 
     if (categoriesDS == null) 
     { 
      categoriesDS = _dal.GetCategoriesTables(); 
     } 
     return categoriesDS; 
    } 
    set 
    { 
     categoriesDS = value; 
     if (this.PropertyChanged != null) 
     { 
      this.PropertyChanged(this, 
        new PropertyChangedEventArgs("CategoriesDS")); 
     } 
    } 
} 

내 데이터 집합은 두 테이블과 첫 번째 테이블 ("MainCategories") 3 개 행이 포함되어 있습니다. 앱을 실행하면 "MainCategories"테이블의 첫 번째 행 만 보입니다.

ListBox가 단지 1 행만 표시하는 이유는 무엇입니까? 나는 전체 표를 보여주고 싶다.

감사합니다.

+0

public DataView MainCategories { get { return CategoriesDS.MainCategories.DefaultView; } } 

또는

public DataView MainCategories { get { return CategoriesDS.Tables[0].DefaultView; } } 

XAML을 테이블을 돌아보십시오. 데이터 세트가 아닙니다. – Paparazzi

답변

1

테이블에 직접 바인딩해야합니다. 당신은 방금 CategoriesDS 속성을 액세스하는 다른 속성을 만든 다음 새 속성에 바인딩 할 수 있습니다 :

<ListBox BorderBrush="#6797c8" BorderThickness="2" 
    ItemsSource="{Binding Path=MainCategories}" 
    DisplayMemberPath="Category"/> 
관련 문제