You can use ListBoxc WrapPanelfor your panel type, and then use a DataTemplate that uses an element Imagefor the icon and a TextBlock for their title.
EG:
public class MyItemType
{
public byte[] Icon { get; set; }
public string Title { get; set; }
}
In window.xaml.cs:
public List<MyItemType> MyItems { get; set; }
public Window1()
{
InitializeComponent();
MyItems = new List<MyItemType>();
MyItemType newItem = new MyItemType();
newItem.Image = ... load BMP here ...;
newItem.Title = "FooBar Icon";
MyItems.Add(newItem);
this.MainGrid.DataContext = this;
}
When loading an icon, see the Microsoft Imaging Overview , as there are many ways to do this.
Then in the .xaml window:
<Window x:Class="MyApplication.Window1"
xmlns:local="clr-namespace:MyApplication"
>
<Window.Resources>
<DataTemplate DataType="{x:Type local:MyItemType}">
<StackPanel>
<Image Source="{Binding Path=Icon}"/>
<TextBlock Text="{Binding Path=Title}"/>
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid Name="MainGrid">
<ListBox ItemsSource="{Binding Path=MyItems}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Grid>
source
share