Novice
Novice

Reputation: 2487

Data Binding In WPF

I have a an instance of class A;

class A
{
    ICollection<B> collec.....
}

class B
{
   C propC....;
}
class C
{
     string Name;
}

I pass instance as the datacontext to a Window and had set collec as ItemCollectionSource for the grid. Is it possible to display the Name property of C in the DataGrid. Other properties are set if i give the Binding Property.

Thanks..

Upvotes: 0

Views: 75

Answers (3)

Aaron McIver
Aaron McIver

Reputation: 24713

Nested properties can be referenced within a binding expression as such...

<TextBlock Text={Binding propC.Name} />

...where I'm assuming propC is indeed a publicly exposed property. You will also need to make sure that Name is also a publicly exposed property.

Upvotes: 1

BrokenGlass
BrokenGlass

Reputation: 160922

You are using private fields currently, try it with a public property instead.

class C
{
     public string Name {get;set;}
}

Upvotes: 0

Nicolas Repiquet
Nicolas Repiquet

Reputation: 9265

Make C.Name a property rather than a field, and bind on propC.Name

Upvotes: 0

Related Questions