私は、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
toと Book も変更するstrings
と、すべてが問題なくスムーズに進みます。StringBuilder
からへの変換をstring
コンソール出力で毎回チェックしstrings
ますが、私の StringBuilder は問題ありません。私は何か間違ったことをしていますか?