我有一个类,为了实验起见,称它为foo(),另一个类称它为bar()。
我在XAML中为类foo()定义了一个数据模板,但是foo()的一个属性是bar()对象,这样
foo()
{
Public string Name {get; set;}
Public int ID {get; set;}
Public bar barProp {get; set;}
}
和
bar()
{
Public string Description{get; set;}
}
我希望我的foo数据模板显示栏的描述属性。
我试过简单的
<textblock Text="{Binding Path=barProp.Description}" />
而且变种也无济于事
寻求智慧,
流行音乐播音员
编辑:
根据要求提供更多信息…
这是我真正的课程…
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}
}
下面是用于模板化它们的XAML…
<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>
准确的问题是accountNumber.name值没有显示在accountRecord元素的expander头中。