views:

62

answers:

2

Hi guys,

I have a class, for experiment sake call it foo() and another class, call it bar()
I have a data template for class foo() defined in my xaml, but one of foo()'s properties is a bar() object such that

foo()
{
    Public string Name {get; set;}
    Public int ID {get; set;}
    Public bar barProp {get; set;}
}

and

bar()
{
    Public string Description{get; set;}
}

I want my data template of foo to display the Description property of bar. I have tried the simple <textblock Text="{Binding Path=barProp.Description}" /> and variants to no avail

Seeking wisdom,
DJ

EDIT: In accordance with requests for more information...
here are my real classes...

public class AccountRecord
{
    public string Value { get; set; }
    public string Identifier { get; set; }
    public Field AccountNumber;
}
public class Field
{
    public string Name{get;set;}
    public string Value{get;set}
}

and here is the XAML used to template them them...

<ListBox Margin="0,35,0,0" Name="listAccountRecords" Background="Transparent" BorderBrush="Transparent" ItemsSource="{Binding AccountRecords, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}">
    <ListBox.ItemTemplate>
            <DataTemplate DataType="{x:Type lib:AccountRecord}">
                <Expander Header="{Binding AccountNumber.Name}">                               
                    <ListView ItemsSource="{Binding Fields}" ItemTemplate="{DynamicResource FieldTemplate}">
                    </ListView>
                </Expander>
            </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

And the exact problem is that the AccountNumber.Name value is not showing up in the expander header for the AccountRecord element

A: 

Try This

<textblock Text="{Binding Path=FooObjectName.barProp.Description}" />

Hope this will work.. Good Luck !

Johnny
Thanks for your comment :) i already tried that, i was confused when it didnt work so i thought something more sinister was at work. a more complete example is available for your perusal :)
TerrorAustralis
+4  A: 

Your "AccountNumber" member (of type "Field") is only a field, not a property. You can only bind to properties. Give it a getter and setter and it'll start working.

Matt Hamilton
Perfect! thanks so much mate, wouldnt have noticed that one...
TerrorAustralis
@Terror it's definitely a FAQ when it comes to WPF binding. It needs to be more visibly documented somehow.
Matt Hamilton