2016-08-11 36 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

謝謝你的工作。 –