将数据模板元素绑定到子类的属性
我有一个类,为了实验起见,将其称为 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 属性。 我尝试了简单的
和变体,但无济于事
寻求智慧,
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 元素的扩展标头中
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的“AccountNumber”成员(类型为“Field”)只是一个字段,而不是一个属性。您只能绑定到属性。给它一个 getter 和 setter,它就会开始工作。
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.
试试这个
希望这会起作用..
祝你好运 !
Try This
Hope this will work..
Good Luck !