gpt4 book ai didi

Silverlight - 在列表框模板中绑定(bind)列表框

转载 作者:行者123 更新时间:2023-12-04 06:25:09 24 4
gpt4 key购买 nike

在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>

报告标题的绑定(bind)有效,但每个报告的内部列表框都是空的。

参数列表已填充。

我究竟做错了什么?

谢谢!

最佳答案

您的“参数”列表是一个公共(public)字段 不是 一个属性,silverlight 只能绑定(bind)到属性而不是字段。尝试将您的类(class)更改为:

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; }
}

这应该按照您想要的方式工作。

关于Silverlight - 在列表框模板中绑定(bind)列表框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6125524/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com