ComboBoxStyle.xaml 16 KB
<ResourceDictionary
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
	<Style x:Key="ComboBoxFocusVisual">
		<Setter Property="Control.Template">
			<Setter.Value>
				<ControlTemplate>
					<Rectangle Margin="4,4,21,4" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
	<Geometry x:Key="DownArrowGeometry">M 0 0 L 3.5 4 L 7 0 Z</Geometry>
	<Style x:Key="ComboBoxReadonlyToggleButton" TargetType="{x:Type ToggleButton}">
		<Setter Property="OverridesDefaultStyle" Value="true"/>
		<Setter Property="IsTabStop" Value="false"/>
		<Setter Property="Focusable" Value="false"/>
		<Setter Property="ClickMode" Value="Press"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type ToggleButton}">
					<Border x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true" CornerRadius="3" BorderThickness="{TemplateBinding BorderThickness}">
						<Grid HorizontalAlignment="Right" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
							<Path x:Name="Arrow" Data="{StaticResource DownArrowGeometry}" Fill="Black" HorizontalAlignment="Center" Margin="3,1,0,0" VerticalAlignment="Center"/>
						</Grid>
					</Border>
					<ControlTemplate.Triggers>										
						<Trigger Property="IsEnabled" Value="false">
							<Setter Property="Fill" TargetName="Arrow" Value="#AFAFAF"/>
						</Trigger>
												
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>		
	</Style>
	<ControlTemplate x:Key="ComboBoxReadonlyTemplate" TargetType="{x:Type ComboBox}">
		<Grid x:Name="MainGrid" SnapsToDevicePixels="true">
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="*"/>
				<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/>
			</Grid.ColumnDefinitions>
			<Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
				<Grid MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=MainGrid}">
					<Border x:Name="DropDownBorder" BorderBrush="{DynamicResource GrayDarkBrush}" BorderThickness="1" Background="{DynamicResource TabControlBackgroundBrush}"
					 CornerRadius="0,0,3,3">
                        <ScrollViewer x:Name="DropDownScrollViewer" Style="{DynamicResource ScrollViewerStyle}">
							<Grid x:Name="grid" RenderOptions.ClearTypeHint="Enabled">
								<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
							</Grid>
						</ScrollViewer>
					</Border>
				</Grid>
			</Popup>
			<ToggleButton BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ComboBoxReadonlyToggleButton}" Foreground="{TemplateBinding Foreground}" BorderThickness="{TemplateBinding BorderThickness}"/>
			<ContentPresenter ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" Content="{TemplateBinding SelectionBoxItem}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsHitTestVisible="false" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
		</Grid>
					<ControlTemplate.Triggers>						
						<Trigger Property="HasItems" Value="false">
							<Setter Property="Height" TargetName="DropDownBorder" Value="95"/>
						</Trigger>
						<Trigger Property="IsEnabled" Value="false">
							<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
							<Setter Property="Background" Value="#FFF4F4F4"/>
						</Trigger>
						<Trigger Property="IsGrouping" Value="true">
							<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
						</Trigger>
						<Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="false"/>
					</ControlTemplate.Triggers>
				</ControlTemplate>
	<Style x:Key="ComboBoxEditableTextBox" TargetType="{x:Type TextBox}">
		<Setter Property="OverridesDefaultStyle" Value="true"/>
		<Setter Property="AllowDrop" Value="true"/>
		<Setter Property="MinWidth" Value="0"/>
		<Setter Property="MinHeight" Value="0"/>
		<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
		<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
		<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type TextBox}">
					<ScrollViewer x:Name="PART_ContentHost" Background="Transparent" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
	<Style x:Key="ComboBoxEditableToggleButton" TargetType="{x:Type ToggleButton}">
		<Setter Property="OverridesDefaultStyle" Value="true"/>
		<Setter Property="IsTabStop" Value="false"/>
		<Setter Property="Focusable" Value="false"/>
		<Setter Property="ClickMode" Value="Press"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type ToggleButton}">
					<Border x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" 
							BorderThickness="1,0,0,0" CornerRadius="0,3,3,0">
						<Path x:Name="Arrow" Data="{StaticResource DownArrowGeometry}" Fill="Black" HorizontalAlignment="Center" Margin="0,1,0,0" VerticalAlignment="Center"/>
					</Border>
					<ControlTemplate.Triggers>
						<Trigger Property="IsChecked" Value="True">
							<Setter Property="Background" TargetName="Chrome" Value="{DynamicResource TabItemSelectedBackground}"/>
							<Setter Property="BorderBrush" TargetName="Chrome" Value="{DynamicResource ButtonNormalBorder}"/>
						</Trigger>
						<Trigger Property="IsEnabled" Value="false">
							<Setter Property="Fill" TargetName="Arrow" Value="#AFAFAF"/>
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>		
	</Style>
    <ControlTemplate x:Key="ComboBoxEditableTemplate" TargetType="{x:Type ComboBox}">
        <Border BorderBrush="{TemplateBinding BorderBrush}" Background="Transparent" Grid.ColumnSpan="2" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3">
		<Grid x:Name="Placement" SnapsToDevicePixels="true">
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="*"/>
				<ColumnDefinition Width="Auto"/>
			</Grid.ColumnDefinitions>
			<Popup x:Name="PART_Popup" 
				   AllowsTransparency="true" 
			       Grid.ColumnSpan="2" 
				   IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" 
				   Margin="1" 
				   PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" 
				   Placement="Bottom">
				<Grid MaxHeight="{TemplateBinding MaxDropDownHeight}" 
					  MinWidth="{Binding ActualWidth, ElementName=Placement}">
					<Border x:Name="DropDownBorder" BorderBrush="{DynamicResource GrayDarkBrush}"  BorderThickness="1" Background="{DynamicResource TabControlBackgroundBrush}" 
							 CornerRadius="0,0,3,3">
                            <ScrollViewer x:Name="DropDownScrollViewer" Style="{DynamicResource ScrollViewerStyle}">
							<Grid x:Name="grid" RenderOptions.ClearTypeHint="Enabled">
								<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
							</Grid>
						</ScrollViewer>
					</Border>
				</Grid>
			</Popup>
			<Grid Margin="0,-1,0,0">			
			
				<TextBox x:Name="PART_EditableTextBox" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" Margin="{TemplateBinding Padding}" Style="{StaticResource ComboBoxEditableTextBox}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
			</Grid>
			<ToggleButton x:Name="toggleButton" Grid.Column="1" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ComboBoxEditableToggleButton}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" Foreground="{DynamicResource ForegroundNormalColorBrush}"/>
		</Grid>
		</Border>
		<ControlTemplate.Triggers>
			<Trigger Property="IsKeyboardFocusWithin" Value="true">
				<Setter Property="Foreground" Value="Black"/>
			</Trigger>
			<Trigger Property="HasItems" Value="false">
				<Setter Property="Height" TargetName="DropDownBorder" Value="95"/>
			</Trigger>
			<Trigger Property="IsEnabled" Value="false">
				<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
				<Setter Property="Background" Value="#FFF4F4F4"/>
			</Trigger>
			<Trigger Property="IsGrouping" Value="true">
				<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
			</Trigger>
		</ControlTemplate.Triggers>
	</ControlTemplate>
		<Style x:Key="ComboBoxItemStyle" TargetType="{x:Type ComboBoxItem}">
			<Setter Property="Background" Value="Transparent"/>
			<Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
			<Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
			<Setter Property="Padding" Value="5,2,0,2"/>
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="{x:Type ComboBoxItem}">
						<Grid Background="{TemplateBinding Background}">
							<VisualStateManager.VisualStateGroups>
								<VisualStateGroup x:Name="CommonStates">
									<VisualState x:Name="Normal"/>
									<VisualState x:Name="MouseOver">
										<Storyboard>
											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="MouseOverBorder">
												<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
											</ObjectAnimationUsingKeyFrames>
										</Storyboard>
									</VisualState>
									<VisualState x:Name="Disabled"/>
								</VisualStateGroup>
								<VisualStateGroup x:Name="SelectionStates">
									<VisualState x:Name="Unselected"/>
									<VisualState x:Name="Selected">
										<Storyboard>
											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="SelectedBorder">
												<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
											</ObjectAnimationUsingKeyFrames>
										</Storyboard>
									</VisualState>
									<VisualState x:Name="SelectedUnfocused">
										<Storyboard>
											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="SelectedBorder">
												<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
											</ObjectAnimationUsingKeyFrames>
										</Storyboard>
									</VisualState>
								</VisualStateGroup>
								<VisualStateGroup x:Name="ValidationStates">
									<VisualState x:Name="Valid"/>
									<VisualState x:Name="InvalidFocused"/>
									<VisualState x:Name="InvalidUnfocused"/>
								</VisualStateGroup>
							</VisualStateManager.VisualStateGroups>
							<Border x:Name="SelectedBorder" SnapsToDevicePixels="true" BorderThickness="0,1,1,1" BorderBrush="{DynamicResource ButtonDefaultStateBackground}" Background="{DynamicResource ButtonNormalBackground}" Visibility="Collapsed"/>


							<Border x:Name="MouseOverBorder" SnapsToDevicePixels="true" BorderThickness="0,1,1,1" BorderBrush="{DynamicResource ButtonDefaultStateBackground}"  Visibility="Collapsed">
								<Grid>
									<Rectangle Fill="{DynamicResource ButtonNormalBackground}" />
									<Rectangle Fill="{DynamicResource ButtonNormalBackground2}" OpacityMask="{DynamicResource TileQuadroBrushWhite}"/>
									<Rectangle Opacity="0.9" Visibility="Visible" Fill="{DynamicResource ListBoxMouseOverItemBrush}"/>								
								</Grid>
							</Border>
							<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}"/>
						</Grid>
						<ControlTemplate.Triggers>
							<Trigger Property="IsEnabled" Value="false">
								<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
							</Trigger>
						</ControlTemplate.Triggers>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
			<Setter Property="BorderBrush" Value="Black"/>
			<Setter Property="BorderThickness" Value="0,1,1,1"/>
			<Setter Property="Width" Value="Auto"/>
			<Setter Property="Height" Value="Auto"/>
			<Setter Property="Foreground" Value="{DynamicResource ForegroundNormalColorBrush}"/>	
		<Style.Triggers>
				<Trigger Property="Selector.IsSelected" Value="True">
					<Setter Property="Foreground" Value="{DynamicResource ButtonForeground}"/>
				</Trigger>
				<Trigger Property="IsMouseOver" Value="True">
					<Setter Property="Foreground" Value="{DynamicResource ButtonForeground}"/>
				</Trigger>
			</Style.Triggers>
	</Style>

	<Style x:Key="ComboBoxStyle" TargetType="{x:Type ComboBox}">
		<Setter Property="FocusVisualStyle" Value="{StaticResource ComboBoxFocusVisual}"/>
		<Setter Property="Foreground" Value="{DynamicResource ForegroundNormalColorBrush}"/>
		<Setter Property="Background" Value="{DynamicResource TabItemNormalBackground}"/>
        <Setter Property="BorderBrush" Value="{DynamicResource ButtonNormalBorder}"/>
        <Setter Property="BorderThickness" Value="1"/>
		<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
		<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
		<Setter Property="Padding" Value="8,2,4,2"/>
		<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
		<Setter Property="ScrollViewer.PanningMode" Value="Both"/>
		<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
		<Setter Property="Template" Value="{DynamicResource ComboBoxReadonlyTemplate}"/>
		<Setter Property="SnapsToDevicePixels" Value="True"/>
		<Setter Property="ItemContainerStyle" Value="{DynamicResource ComboBoxItemStyle}"/>
		<Setter Property="VerticalContentAlignment" Value="Center"/>
		<Style.Triggers>
			<Trigger Property="IsEditable" Value="true">				
				<Setter Property="IsTabStop" Value="false"/>
				<Setter Property="Padding" Value="3"/>
				<Setter Property="Template" Value="{DynamicResource ComboBoxEditableTemplate}"/>
			</Trigger>	
			<Trigger Property="IsMouseOver" Value="True">
				<Setter Property="BorderBrush" Value="{DynamicResource ButtonCheckingColorBrush}"/>							
			</Trigger>	
			<Trigger Property="IsDropDownOpen" Value="True">
				<Setter Property="Background" Value="{DynamicResource TabItemSelectedBackground}"/>
				<Setter Property="BorderBrush" Value="{DynamicResource ButtonNormalBorder}"/>
			</Trigger>										
		</Style.Triggers>
	</Style>
</ResourceDictionary>