显示网格的图像与WPF [英] Displaying images in grid with WPF

查看:219
本文介绍了显示网格的图像与WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建与它内部商店的应用程序,所以我需要的物品的文字图标的网格视图。 iTunes为的什么,我需要一个很好的例子。 ?任何想法

I'm creating an application with a store inside of it, so I need a grid view for items' icons with text. iTunes gives a good example of what I need. Any ideas?

HTTP://i55.tinypic .COM / 16jld3a.png

推荐答案

您可以使用的ListBox 具有 WrapPanel 其面板类型,然后使用一个使用图片元素的图标一个DataTemplate ,并为他们的标题TextBlock的

You could use a ListBox that has a WrapPanel for its panel type, then use a DataTemplate that uses an Image element for the icon and a TextBlock for their caption.

例如:

public class MyItemType
{
    public byte[] Icon { get; set; }

    public string Title { get; set; }
}

在window.xaml.cs:

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;
}

当加载图标,请参阅的Microsoft's成像概述,因为有很多方法可以做到这一点。

When loading the icon, refer to Microsoft's Imaging Overview since there are a lot of ways to do it.

然后在window.xaml:

Then in 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>

这篇关于显示网格的图像与WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆