locked
How to bind nested properties to the data template? RRS feed

  • Question

  • Note:This is the same post which I've posted on http://stackoverflow.com/questions/8622763/databinding-how-to-bind-nested-properties-to-the-data-template but no answer has been given yet.

    I have a data template

    <DataTemplate x:Key="MyPivotItemTemplate">
            <controls:PivotItem Header="{Binding MyClassAName}" />
    </DataTemplate>

    in which I've utilized in

    <controls:Pivot Title="Category" x:Name="myPivot" ItemTemplate="{StaticResource MyPivotItemTemplate}">

    in which I try to pass on a list of ClassA as the pivot item source, which is defined as below

    Class ClassA
    {
       String MyClassAName;
       ...
    }
    ...
    ClassA myClassAItem = new ClassA() {MyClassAName = "LOL"};
    ClassACollection.Add(myClassAItem);
    ...
    myPivot.ItemSource = ClassACollection;

    When I try to run the code, the added pivotitem header text is the object name of the collection provided (ie "MyApp.ClassACollection") instead of the value of ClassA's MyClassAName value (ie "LOL"). So how can I bind the each of ClassA item's MyClassAName to each of the dynamically created pivotitem's header?

    Thanks!

    Tuesday, December 27, 2011 10:33 PM

Answers

  • Hi Frankie,

    You can do 

    <controls:PivotItem Header="{Binding ClassA.MyClassAName}" /> in binding.
    I think this will work.
    Wednesday, December 28, 2011 9:25 AM

All replies

  • Hi Frankie,

    You can do 

    <controls:PivotItem Header="{Binding ClassA.MyClassAName}" /> in binding.
    I think this will work.
    Wednesday, December 28, 2011 9:25 AM
  • for better binding uer properties window of each control. this with show you the exact path of your property

    Tuesday, February 14, 2012 6:31 AM