Created
August 31, 2018 06:51
-
-
Save satr/60cca06831848e87b8b02fee2c30bbc2 to your computer and use it in GitHub Desktop.
WPF ComboBox with a title in the popup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="WpfApp1.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" | |
mc:Ignorable="d" | |
Title="MainWindow" Height="450" Width="800"> | |
<Window.Resources> | |
<Style TargetType="ComboBox"> | |
<Setter Property="Template"> | |
<Setter.Value> | |
<ControlTemplate TargetType="ComboBox"> | |
<Grid> | |
<ToggleButton x:Name="DropDownToggle" | |
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" | |
Margin="-1" HorizontalContentAlignment="Right" | |
IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay, | |
RelativeSource={RelativeSource TemplatedParent}}"> | |
<Path x:Name="BtnArrow" Height="4" Width="8" | |
Stretch="Uniform" Margin="0,0,6,0" Fill="Black" | |
Data="F1 M 300,-190L 310,-190L 305,-183L 301,-190 Z " /> | |
</ToggleButton> | |
<ContentPresenter x:Name="ContentPresenter" Margin="6,2,25,2" | |
Content="{TemplateBinding SelectionBoxItem}" | |
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" | |
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" /> | |
<TextBox x:Name="PART_EditableTextBox" | |
Style="{x:Null}" | |
Focusable="False" | |
Background="{TemplateBinding Background}" | |
HorizontalAlignment="Left" | |
VerticalAlignment="Center" | |
Margin="3,3,23,3" | |
Visibility="Hidden" | |
IsReadOnly="{TemplateBinding IsReadOnly}" /> | |
<Popup x:Name="PART_Popup" | |
IsOpen="{TemplateBinding IsDropDownOpen}"> | |
<Border x:Name="PopupBorder" | |
HorizontalAlignment="Stretch" Height="Auto" | |
MinWidth="{TemplateBinding ActualWidth}" | |
MaxHeight="{TemplateBinding MaxDropDownHeight}" | |
BorderThickness="{TemplateBinding BorderThickness}" | |
BorderBrush="Black" Background="White" CornerRadius="3"> | |
<StackPanel> | |
<Label>My title here</Label> | |
<ScrollViewer x:Name="ScrollViewer" BorderThickness="0" Padding="1"> | |
<ItemsPresenter /> | |
</ScrollViewer> | |
</StackPanel> | |
</Border> | |
</Popup> | |
</Grid> | |
</ControlTemplate> | |
</Setter.Value> | |
</Setter> | |
</Style> | |
</Window.Resources> | |
<Grid> | |
<ComboBox Height="26" Width="150"> | |
<ComboBoxItem Name="Item1">Item1</ComboBoxItem> | |
<ComboBoxItem Name="Item2">Item2</ComboBoxItem> | |
<ComboBoxItem Name="Item3">Item3</ComboBoxItem> | |
<ComboBoxItem Name="Item4">Item4</ComboBoxItem> | |
</ComboBox> | |
</Grid> | |
</Window> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment