开发者

Display image in combobox column in 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?


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>

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜