2016-08-11 56 views
0

所以我进入项目与此C#代码列表框:绑定列表框项目模板,以可变

 void GetItems() { 
    VideoListBox.ItemsSource = from list1 in xmlfeedresult.Descendants("video") 
            select new VideoItem 
            { 
             Username = list1.Element("u").Value, 
             Thumbnail = list1.Element("i").Value, 
             Description = list1.Element("d").Value 
            }; 

    } 

    public class VideoItem 
    { 
     public string Username; 
     public string Thumbnail; 
     public string Description; 
    } 

这是XAML代码所使用

<ListBox Height="588" Margin="272,101,272,0" Name="VideoListBox" VerticalAlignment="Top"> 
     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <StackPanel Orientation="Horizontal" Height="132"> 
        <Image Source="{Binding Thumbnail }" Height="300" Width="500" VerticalAlignment="Top" Margin="0,10,8,0"/> 
        <StackPanel Width="370"> 
         <TextBlock Text="{Binding Username}" Foreground="#FFC8AB14" FontSize="28" /> 
         <TextBlock Text="{Binding Description}" TextWrapping="Wrap" FontSize="24" /> 
        </StackPanel> 
       </StackPanel> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
    </ListBox> 

的问题是,它将在列表框中生成三个项目,但用户名,缩略图和描述中的值不会显示。它只有三个完全黑色的物品。 希望得到任何帮助。

回答

2

你的价值应该是公开的属性,不只是字段。

public class VideoItem 
{ 
    public string Username {get; set;} 
    public string Thumbnail {get; set;} 
    public string Description {get; set;} 
} 
+0

谢谢你的工作。 –