Click here to Skip to main content
15,885,048 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

XML
<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>
Posted

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.
 
Share this answer
 
data is hardcoded to make it easier.
 
Share this answer
 
Comments
Christian Graus 31-Aug-10 6:45am    
Please don't push 'answer' to comment or ask questions. No, it makes it impossible, or at least, harder. You should create a template with triggers to change how the data is presented based on if it's selected or not. Then you can just bind to whatever data you like and it will work. The way you're doing it is fighting every feature WPF provides for you to do what you want.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900