ListBoxStyle.xaml 7.05 KB
<ResourceDictionary
	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">
	<ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="..\Colors\Colors.xaml"/>
	</ResourceDictionary.MergedDictionaries>
	<SolidColorBrush x:Key="ListBorder" Color="#828790"/>
	<!-- Resource dictionary entries should be defined here. -->
	<Style x:Key="ListBoxStyle" TargetType="{x:Type ListBox}">
		<Style.Triggers>
			<Trigger Property="Selector.IsSelected" Value="True">
				<Setter Property="Foreground" Value="{DynamicResource ButtonForeground}"/>
			</Trigger>
		</Style.Triggers>
		<Setter Property="ItemContainerStyle" Value="{DynamicResource ListBoxItemStyle}"/>
		<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
		<Setter Property="BorderBrush" Value="{StaticResource ListBorder}"/>
		<Setter Property="BorderThickness" Value="1"/>
		<Setter Property="Foreground" Value="{DynamicResource ForegroundNormalColorBrush}"/>
		<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
		<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
		<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
		<Setter Property="ScrollViewer.PanningMode" Value="Both"/>
		<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
		<Setter Property="VerticalContentAlignment" Value="Center"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type ListBox}">
					<Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
						<Border BorderThickness="3,0,0,0" BorderBrush="{DynamicResource ButtonNormalBackground}">
							<ScrollViewer Focusable="false" Padding="{TemplateBinding Padding}"
                                          Style="{DynamicResource ScrollViewerStyle}">
								<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="{TemplateBinding Padding}"/>
							</ScrollViewer>
						</Border>
					</Border>
					<ControlTemplate.Triggers>
						<Trigger Property="IsEnabled" Value="false">
							<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
						</Trigger>
						<Trigger Property="IsGrouping" Value="true">
							<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
	<Style x:Key="ListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
		<Style.Triggers>
			<Trigger Property="IsMouseOver" Value="True">
				<Setter Property="Foreground" Value="{DynamicResource ButtonForeground}"/>
			</Trigger>
			<MultiTrigger>
				<MultiTrigger.Conditions>
					<Condition Property="Selector.IsSelected" Value="True"/>
					<Condition Property="IsMouseOver" Value="False"/>
				</MultiTrigger.Conditions>
				<Setter Property="Foreground" Value="{DynamicResource ButtonForeground}"/>
			</MultiTrigger>
			
		</Style.Triggers>
		<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,3"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type ListBoxItem}">
					<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 GrayMiddleBrush}"/>
						</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>
</ResourceDictionary>