如何解决Silverlight-在列表框模板中绑定列表框
| 在Silverlight中,我试图构建报告列表框,并且试图在外部报告列表框的数据模板内的列表框中显示报告的参数。 以下是数据类: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:
<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>
报表标题的绑定有效,但是每个报表的内部列表框为空。
将填充“参数”列表。
我究竟做错了什么?
谢谢!
解决方法
您的\“ Parameters \”列表是一个公共字段,而不是属性,silverlight只能绑定到属性,而不能绑定到字段。尝试将您的班级更改为此:
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; }
}
这应该按照您想要的方式工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。