【问题标题】:Silverlight - binding a listbox within a listbox templateSilverlight - 在列表框模板中绑定列表框
【发布时间】:2011-09-01 19:16:20
【问题描述】:

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

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

参数列表已填充。

我做错了什么?

谢谢!

【问题讨论】:

    标签: silverlight xaml binding listbox


    【解决方案1】:

    您的“参数”列表是一个公共字段不是属性,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; }
    }
    

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

    【讨论】:

    • 感谢 Viggity!像魅力一样工作!
    猜你喜欢
    • 2011-05-27
    • 1970-01-01
    • 2011-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多