You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.9 KiB

2 years ago
<Window x:Class="ComboBoxSample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ComboBoxSample"
mc:Ignorable="d"
Title="MainWindow" Height="400" Width="400">
<Window.DataContext>
<local:ColorList/>
</Window.DataContext>
<StackPanel>
<Label Content="Color" HorizontalAlignment="Center" FontWeight="Bold"/>
<ComboBox Width="200" HorizontalAlignment="Center" SelectedIndex="0">
<ComboBoxItem>
<StackPanel Orientation="Horizontal">
<Ellipse Fill="Red" Width="15" Height="15" Margin="0 0 5 0"/>
<TextBlock Text="Red"/>
</StackPanel>
</ComboBoxItem>
<ComboBoxItem>
<StackPanel Orientation="Horizontal">
<Ellipse Fill="Green" Width="15" Height="15" Margin="0 0 5 0"/>
<TextBlock Text="Green"/>
</StackPanel>
</ComboBoxItem>
<ComboBoxItem Content="Blue"/>
<ComboBoxItem Content="Orange"/>
</ComboBox>
<Label Content="Color from list" HorizontalAlignment="Center" FontWeight="Bold"/>
<ComboBox Width="200" ItemsSource="{Binding}" SelectedIndex="0">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Ellipse Fill="{Binding}" Width="15" Height="15" Margin="0 0 5 0"/>
<TextBlock Text="{Binding}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
</Window>