2011-05-25 63 views
2

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

为报告工作的标题绑定,但其内每个报告的列表框都是空的。

填充参数列表。

我在做什么错?

谢谢!

回答

3

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

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

+0

谢谢Viggity!像魅力一样工作! – 2011-05-25 17:01:52

+0

高兴地帮助:) – viggity 2011-05-27 13:11:14

+0

感谢x1000!只有我和谷歌4小时才能找到... – Matt 2014-01-15 19:59:57