在datagrid中的combobox列中显示图像 [英] Display image in combobox column in datagrid

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

问题描述

我想在datagrid中有一个组合框来显示实际图像的列表,而不是文本。

I'd like to have a combobox in a datagrid to show a list of actual images, instead of text.

我可以通过手动构建组合框来实现此功能,但似乎无法通过绑定(这是数据网格可以使用的唯一方法)。

I can make this work by manually building a combobox, but cant seem to do this via binding (which is about the only way the datagrid can be used).

我还尝试了一个模板列,,但得到了相同的结果 - 显示图像名称的文本列表类。任何样品展示这个?

I also tried a template column, but got the same results- listing of text showing the name of the image class. Any samples demonstrating this?

推荐答案

根据需要嵌入尽可能多的模板,如果您的 ComboBox 显示类名只是设置 ComboBox.ItemTemplate 来与你的课程做一些事情。这里我假设 MyImageList 包含 ImageSource 对象(需要更多的大小规格):

Nest as many templates as you need, if your ComboBox shows the class name just set ComboBox.ItemTemplate to do something with your class. Here i assume that MyImageList consists of ImageSource objects (needs some more sizing specifications):

<DataGridTemplateColumn>
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <ComboBox ItemsSource="{Binding MyImageList}">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <Image Source="{Binding}"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

或者你可以大胆地使用一个 DataGridComboBoxColumn 好吧,只需使用 CellStyle 设置一个 DataTemplate 即可显示您的图像:

Alternatively you could porbably use a DataGridComboBoxColumn as well, just use the CellStyle to set up a DataTemplate which can display your images:

<DataGridComboBoxColumn ItemsSource="{Binding MyImageList}">
    <DataGridComboBoxColumn.CellStyle>
        <Style TargetType="ComboBox">
            <Setter Property="ItemTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Image Source="{Binding}"/>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </DataGridComboBoxColumn.CellStyle>
</DataGridComboBoxColumn>

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

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