【发布时间】:2011-02-23 23:57:03
【问题描述】:
我有一个类,为了实验起见称它为 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 数据模板显示 bar 的 Description 属性。
我尝试了简单的<textblock Text="{Binding Path=barProp.Description}" /> 和变体无济于事
求智慧,
DJ
编辑:
根据要求提供更多信息...
这是我真正的课程...
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 元素的扩展标题中
【问题讨论】:
-
应该没问题。 WPF 的绑定系统完全支持嵌套属性。你看到了什么行为?您可能需要发布一个更具体的示例。
-
检查 TextBlock.DataContext 属性 - 验证它是否设置为 Foo 类型的实例。绑定似乎是正确的。
-
我已经添加了我正在处理的确切案例
标签: c# wpf xaml binding datatemplate