Вы можете использовать ListBox
, который имеет WrapPanel
для своего типа панели, а затем использовать DataTemplate, который использует элемент Image
для значка и TextBlock для их заголовка.
EG:
public class MyItemType
{
public byte[] Icon { get; set; }
public string Title { get; set; }
}
В 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;
}
При загрузке значка см. Обзор изображений Microsoft , поскольку для этого существует множество способов.
Затем в window.xaml:
<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>