1

MVVM に基づく WPF プロジェクトがあります。私の見解では、次の ListBox があります

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

そして、これはViewModelでの私のコードです:

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"));
        }
    }
}

私の DataSet には 2 つのテーブルが含まれており、最初のテーブル (「MainCategories」) には 3 つの行が含まれています。アプリを実行すると、「MainCategories」テーブルの最初の行だけが表示されます。

ListBox に 1 行しか表示されないのはなぜですか? テーブル全体を表示したい。

ありがとう

4

1 に答える 1

1

テーブルに直接バインドする必要があります。プロパティにアクセスするだけCategoriesDSで、新しいプロパティに対してバインドする別のプロパティを作成できます。

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

また

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

XAML

<ListBox BorderBrush="#6797c8" BorderThickness="2" 
    ItemsSource="{Binding  Path=MainCategories}" 
    DisplayMemberPath="Category"/>
于 2012-12-15T20:50:20.077 に答える