2011-04-12 5 views
3

私はDavidです。私はWPFアプリケーションのXAMLでコレクションをDataGridにバインドすることを知らない。ObservableCollection <T>をDatagridにバインドする方法はありますか?

は、以下のクラスです。コード上

class TestSetting(): INotifyChanged 
{ 
    private a 
    public double A 
    { 
     get a; 
     set a = value; 
     Notify("A"); 
    } 

    private b 
    public double B 
    { 
     get b; 
     set b = value; 
     Notify("B"); 
    } 

    private c 
    public double C 
    { 
     get c; 
     set c = value; 
     Notify("C"); 
    } 

} 


class TestCollect():ObservableCollection<T> ,INotifyListener 
{ 

} 

Psedoコードです。

DataContextには7つの項目があります。したがって、グリッドには7つの列があります。誰かが例やコードスニペットで私を助けてくれますか?

答えて

0

のDataContextはTestCollectionが含まれている場合は、必要とされていることすべてが{Binding}

0

へのItemsSourceを設定している私は何が必要なのようなものであることを考える:

あなたviemodel:

public class ViewModel 
{ 
    public ViewModel() 
    { 
     SourceList = new ObservableCollection<BusinessAdapter>(); 

     for (int i = 0; i < 50; i++) 
     { 
      SourceList.Add(new BusinessAdapter { BusinessProperty = "blabla_" + i }); 
     } 
    } 
    public ObservableCollection<BusinessAdapter> SourceList { get; private set; } 
} 

あなたはビューコードの背後にあります

public partial class Window1 : Window 
{ 
    public Window1() 
    { 
     InitializeComponent(); 

     DataContext = new ViewModel(); 

    } 
} 

あなたの意見を聞いてください。ここで重要なものは「のItemsSource = 『{バインディングSOURCELIST}』」です基本的に「私のリストボックスのソースコレクションがSOURCELISTという名前(のViewModelオブジェクトである)私のDataContextの集まりである」意味

 <ListView x:Name="listOne" 
       Grid.Column="0" 
       Width="50" 
       Height="200" 
       ItemsSource="{Binding SourceList}" /> 
0

I初心者ですが、私は私の答えを探ります:

ObservableCollection<YourModel> yourdata = new ObservableCollection<YourModel>(); 
dataGrid.ItemsSource = yourdata; 

第2位です。ステートメントはバインディングを実行します。

関連する問題