与ComboBoxItems模板不同的ComboBox SelectedItem模板 [英] ComboBox SelectedItem Template different than ComboBoxItems Template

查看:62
本文介绍了与ComboBoxItems模板不同的ComboBox SelectedItem模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望组合框的内容项的模板与所选项目不同,例如.下拉菜单包含与名称,但被选中的任何项目时,我想只显示图像的名字不是图像作为选择的图像项目.

I want combobox having contentitem which has template different than selected Item, eg. Dropdown contains items which are images with name but when any item is selected, I want to display only image name not image as selected.

<ComboBox >
                <ComboBoxItem IsSelected="True">
                    <StackPanel Orientation="Horizontal">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="0.7*"/>
                                <RowDefinition Height="0.3*"/>
                            </Grid.RowDefinitions>
                            <Rectangle Stroke="#FFA9CF34" Grid.RowSpan="2" RadiusX="2" RadiusY="2"/>
                            <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1" Grid.RowSpan="2" Margin="2,0,2,2"><Run Text="Level 1"/></TextBlock>
                            <Image Source="D:\Level1.png" HorizontalAlignment="Center" Margin="2,2,2,2" VerticalAlignment="Center" Width="150" Height="100" />
                        </Grid>
                    </StackPanel>
                </ComboBoxItem>
                <ComboBoxItem>
                    <StackPanel Orientation="Horizontal">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="0.7*"/>
                                <RowDefinition Height="0.3*"/>
                            </Grid.RowDefinitions>
                            <Rectangle Stroke="#FFA9CF34" Grid.RowSpan="2" RadiusX="2" RadiusY="2"/>
                            <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1" Grid.RowSpan="2" Margin="2,0,2,2"><Run Text="Level 2"/></TextBlock>
                            <Image Source="D:\Level2.png" HorizontalAlignment="Center" Margin="2,2,2,2" VerticalAlignment="Center" Width="150" Height="100" />
                        </Grid>
                    </StackPanel>
                </ComboBoxItem>
                <ComboBoxItem>
                    <StackPanel Orientation="Horizontal">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="0.7*"/>
                                <RowDefinition Height="0.3*"/>
                            </Grid.RowDefinitions>
                            <Rectangle Stroke="#FFA9CF34" Grid.RowSpan="2" RadiusX="2" RadiusY="2"/>
                            <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1" Grid.RowSpan="2" Margin="2,0,2,2"><Run Text="Level 3"/></TextBlock>
                            <Image Source="D:\Level3.png" HorizontalAlignment="Center" Margin="2,2,2,2" VerticalAlignment="Center" Width="150" Height="100" />
                        </Grid>
                    </StackPanel>
                </ComboBoxItem>
                <ComboBoxItem>
                    <StackPanel Orientation="Horizontal">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="0.7*"/>
                                <RowDefinition Height="0.3*"/>
                            </Grid.RowDefinitions>
                            <Rectangle Stroke="#FFA9CF34" Grid.RowSpan="2" RadiusX="2" RadiusY="2"/>
                            <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1" Grid.RowSpan="2" Margin="2,0,2,2"><Run Text="Level 4"/></TextBlock>
                            <Image Source="D:\Level 4.png" HorizontalAlignment="Center" Margin="2,2,2,2" VerticalAlignment="Center" Width="150" Height="100" />
                        </Grid>
                    </StackPanel>
                </ComboBoxItem>
                <ComboBoxItem>
                    <StackPanel Orientation="Horizontal">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="0.7*"/>
                                <RowDefinition Height="0.3*"/>
                            </Grid.RowDefinitions>
                            <Rectangle Stroke="#FFA9CF34" Grid.RowSpan="2" RadiusX="2" RadiusY="2"/>
                            <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1" Grid.RowSpan="2" Margin="2,0,2,2"><Run Text="Level 5"/></TextBlock>
                            <Image Source="D:\Level 5.png" HorizontalAlignment="Center" Margin="2,2,2,2" VerticalAlignment="Center" Width="150" Height="100" />
                        </Grid>
                    </StackPanel>
                </ComboBoxItem>
                <ComboBoxItem>
                    <StackPanel Orientation="Horizontal">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="0.7*"/>
                                <RowDefinition Height="0.3*"/>
                            </Grid.RowDefinitions>
                            <Rectangle Stroke="#FFA9CF34" Grid.RowSpan="2" RadiusX="2" RadiusY="2"/>
                            <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1" Grid.RowSpan="2" Margin="2,0,2,2"><Run Text="Level 6"/></TextBlock>
                            <Image Source="D:\Level 6.png" HorizontalAlignment="Center" Margin="2,2,2,2" VerticalAlignment="Center" Width="150" Height="100" />
                        </Grid>
                    </StackPanel>
                </ComboBoxItem>
            </ComboBox>

推荐答案

这看起来很复杂,但是它看起来不像模板,它定义了选定或未选定项目的外观,看起来像是硬编码的数据给我.
This looks complex, but it doesn''t look like a template that defines how a selected or non selected item should look, it looks like hard coded data to me.


数据经过硬编码,以便于使用.
data is hardcoded to make it easier.


这篇关于与ComboBoxItems模板不同的ComboBox SelectedItem模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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