Я пытаюсь просмотреть значки и текст в виде таблицы, поэтому код выглядит следующим образом:
MyItemType.cs
public class MyItemType
{
public byte[] Image { get; set; }
public string Title { get; set; }
}
MainWindow.cs
public MainWindow()
{
InitializeComponent();
MemoryStream mstream = new MemoryStream();
Bitmap b = new Bitmap(@"C:\Users\Eliazar\Pictures\1556.bmp");
b.Save(mstream, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] ba = mstream.ToArray();
BinaryWriter writer = new BinaryWriter(mstream);
writer.Write(ba);
MyItems = new List<MyItemType>();
MyItemType newItem = new MyItemType();
newItem.Image = ba;
newItem.Title = "FooBar Icon";
MyItems.Add(newItem);
this.MainGrid.DataContext = this;
}
public List<MyItemType> MyItems { get; set; }
MainWindow.xaml
<Window.Resources>
<DataTemplate DataType="{x:Type local:MyItemType}">
<StackPanel>
<Image Source="{Binding Path=Image}"/>
<TextBlock Text="{Binding Path=Title}"/>
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid Name="MainGrid">
<ListBox ItemsSource="{Binding Path=MyItems}" Background="White" Width="400" HorizontalAlignment="Right" Margin="0,211.206,35,188.794">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Grid>
Но в окне ничего не появляется.Кто-нибудь имеет представление о том, что не так?