Silverlight的 - 一个列表框模板中绑定列表框 [英] Silverlight - binding a listbox within a listbox template
问题描述
在Silverlight中,我试图建立的报告列表框,我试图证明在外部报告列表框的DataTemplate中内的一个列表框报告的参数。
In silverlight, I'm trying to build a listbox of reports and I'm trying to show the parameters of the report in a listbox within the datatemplate of the outer reports listbox.
下面是数据类:
public class Report
{
public string Title { get; set; }
public string Description { get; set; }
public List<ReportParameter> Parameters = new List<ReportParameter>();
}
public class ReportParameter
{
public string Name { get; set; }
public string ParameterType { get; set; }
public bool Required { get; set; }
}
下面是我在试图用做它的XAML:
Here's the XAML I'm trying to use to do it:
<ListBox x:Name="lstReports">
<ListBox.ItemTemplate>
<DataTemplate>
<Border>
<StackPanel>
<TextBlock Text="{Binding Title}"/>
<ListBox ItemsSource="{Binding Parameters}" Height="60" Width="60">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
有关的工作报告的标题绑定,但内心列表框为空,为每个报告。
The binding for the Title of the report works, but the inner listbox is empty for each of the reports.
参数列表填充的。
我在做什么错了?
谢谢!
推荐答案
您的参数列表是一个公共领域的不可以属性,Silverlight的只能绑定属性,而不是字段。试着改变你的类这样的:
Your "Parameters" list is a public field not a property, silverlight can only bind to properties and not fields. Try changing your class to this:
public class Report
{
public Report()
{
Parameters = new List<ReportParameter>();
}
public string Title { get; set; }
public string Description { get; set; }
public List<ReportParameter> Parameters { get; set; }
}
这应该工作,你希望的方式。
This should work the way you want it.
这篇关于Silverlight的 - 一个列表框模板中绑定列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!