我有一个listbox
,我在其中每行传递 5 个项目。我的 XML 文件如下所示:
<ListBox x:Name="DatabaseBox" ItemsSource="{Binding Book}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Width="auto" Height="22">
<Image x:Name="ToggleFavoriteImage" Width="10" Height="10" Tag="{Binding Tag}" Source="{Binding ImageSource}" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding Name}" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Center"/>
<ListBoxItem Content="{Binding City}" HorizontalAlignment="Center"/>
<ListBoxItem Content="{Binding Author}" HorizontalAlignment="Center"/>
<ListBoxItem Content="{Binding Country}" HorizontalAlignment="Center"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
哪里Book
是private static List<BookItems> Book{ get; set; }
和BookItems
是
public struct BookItems
{
public string Name{ get; set; }
public string Url { get; set; }
public string Author{ get; set; }
public string City { get; set; }
public string Country { get; set; }
public string Tag { get; set; }
public ImageSource ImageSource { get; set; }
}
我要传入的所有数据ListBox
都存储在另一个中List
:private static List<Tuple<StringBuilder , StringBuilder , StringBuilder , StringBuilder , StringBuilder >> BookList = new List<Tuple<StringBuilder , StringBuilder , StringBuilder , StringBuilder , StringBuilder >>();
因此,如果我尝试以ListBox
这种方式填写:
foreach(var ListItem in BookList)
{
Book= new List<BookItems>()
{
new BookItems()
{
Tag = ListItem.Item1.ToString(),ImageSource = FavoriteSource, Name= ListItem.Item1.ToString(), Author= ListItem.Item3.ToString(), City = ListItem.Item4.ToString(),Country = ListItem.Item5.ToString()
}
};
DatabaseBox.Items.Add(Book);
}
然后我到处都是,null
除了图像。如果我也更改我BookList
的 tostrings
和我的 Book,那么一切都会顺利进行,没有任何问题。我每次使用控制台输出检查从StringBuilder
到的转换并且我的为空,我的 StringBuilder 是好的。我做错了什么吗?string
strings