嵌套列表框不会显示嵌套列表

时间:2012-01-08 02:18:10

标签: c# windows-phone-7 listbox

   <ListBox Height="434" HorizontalAlignment="Left" Margin="6,238,0,0" Name="listBox1"             VerticalAlignment="Top" Width="432" DataContext="{Binding}"> 

            <ListBox.ItemTemplate> 
                <DataTemplate> 
                    <StackPanel> 
                        <TextBlock Text="{Binding Name}" Margin="4" Foreground="{StaticResource PhoneAccentBrush}"></TextBlock> 
                        <StackPanel Orientation="Horizontal" Margin="4"> 
                            <TextBlock Text="Set" Margin="16" Foreground="{StaticResource PhoneAccentBrush}" /> 
                            <TextBlock Text="Weight" Margin="16" Foreground="{StaticResource PhoneAccentBrush}" /> 
                            <TextBlock Text="Reps" Margin="10,16,0,16" Foreground="{StaticResource PhoneAccentBrush}" /> 
                        </StackPanel> 
                        <ListBox Name="setsAndReps" Height="auto" Width="auto" ItemsSource="{Binding Sets}"> 
                            <ListBox.ItemTemplate> 
                                <DataTemplate> 
                                    <StackPanel Orientation="Horizontal"> 
                                        <TextBox Text="{Binding SetNumber}"/> 
                                        <TextBox Text="{Binding Weight}"/> 
                                        <TextBox Text="{Binding Reps}"/> 
                                    </StackPanel> 
                                </DataTemplate> 
                            </ListBox.ItemTemplate> 
                        </ListBox> 
                    </StackPanel> 
                </DataTemplate> 
            </ListBox.ItemTemplate> 
        </ListBox> 

外部列表框的项目源被设置为一个名为excercise的用户定义类的可观察集合

     public class excercise : IComparable, IEquatable<excercise>, INotifyPropertyChanged 
{ 
    string name; 
    int max; 
    int NUM_SETS; 
    ObservableCollection<set> sets; 
    public event PropertyChangedEventHandler PropertyChanged; 

    public string Name 
    { 
        get { return this.name; } 
        set { this.name = value; } 
    } 
    public excercise(string name) 
    { 
        this.name = name; 
        this.NUM_SETS = 0; 
        this.sets = new ObservableCollection<set>(); 
    } 
   public ObservableCollection<set> Sets
    { 
        get{return this.sets; }
    } 
  public ObservableCollection<set> getSets() 
    { 
        return this.sets; 
    } 
} 

内部列表框中的属性来自set类,但没有显示它们,我不确定是什么问题。

1 个答案:

答案 0 :(得分:0)

您的第一个列表框没有设置任何itemource,并且datacontext设置为空绑定(在代码的第1行)