Default Luna ComboBox Style

<Window
    
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class
="TemplateSample.Window1"
    x:Name
="Window"
    Title
="Window1"
    Width
="640" Height="480"
    xmlns:Microsoft_Windows_Themes
="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Luna">

    
<Window.Resources>
        
<Style x:Key="ComboBoxFocusVisual">
            
<Setter Property="Control.Template">
                
<Setter.Value>
                    
<ControlTemplate>
                        
<Rectangle Stroke="Black" StrokeDashArray="1 2" StrokeThickness="1" Margin="4,4,21,4" SnapsToDevicePixels="true"/>
                    
</ControlTemplate>
                
</Setter.Value>
            
</Setter>
        
</Style>
        
<SolidColorBrush x:Key="ListBorder" Color="#FF7F9DB9"/>
        
<Style x:Key="ComboBoxTransparentButtonStyle" TargetType="{x:Type ToggleButton}">
            
<Setter Property="MinWidth" Value="0"/>
            
<Setter Property="MinHeight" Value="0"/>
            
<Setter Property="Width" Value="Auto"/>
            
<Setter Property="Height" Value="Auto"/>
            
<Setter Property="Background" Value="Transparent"/>
            
<Setter Property="Focusable" Value="false"/>
            
<Setter Property="ClickMode" Value="Press"/>
            
<Setter Property="Template">
                
<Setter.Value>
                    
<ControlTemplate TargetType="{x:Type ToggleButton}">
                        
<Grid SnapsToDevicePixels="true" Background="{TemplateBinding Background}">
                            
<Grid.ColumnDefinitions>
                                
<ColumnDefinition Width="*"/>
                                
<ColumnDefinition Width="Auto" SharedSizeGroup="ComboBoxButton"/>
                            
</Grid.ColumnDefinitions>
                            
<Microsoft_Windows_Themes:ScrollChrome x:Name="Chrome" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Grid.Column="1" HasOuterBorder="false" Padding="1,0,0,0" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsChecked}" Microsoft_Windows_Themes:ScrollChrome.ScrollGlyph="DownArrow" ThemeColor="NormalColor"/>
                        
</Grid>
                    
</ControlTemplate>
                
</Setter.Value>
            
</Setter>
        
</Style>
        
<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="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>
        
<ControlTemplate x:Key="ComboBoxEditableTemplate" TargetType="{x:Type ComboBox}">
            
<Grid SnapsToDevicePixels="true">
                
<Border x:Name="Bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="1">
                    
<Grid Grid.IsSharedSizeScope="true">
                        
<Grid.ColumnDefinitions>
                            
<ColumnDefinition Width="1"/>
                            
<ColumnDefinition Width="*"/>
                            
<ColumnDefinition Width="Auto" SharedSizeGroup="ComboBoxButton"/>
                        
</Grid.ColumnDefinitions>
                        
<TextBox Margin="{TemplateBinding Padding}" x:Name="PART_EditableTextBox" Style="{StaticResource ComboBoxEditableTextBox}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" Grid.Column="1" IsReadOnly="{Binding Path=IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}"/>
                        
<ToggleButton Style="{StaticResource ComboBoxTransparentButtonStyle}" Background="{x:Null}" Grid.ColumnSpan="3" IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"/>
                    
</Grid>
                
</Border>
                
<Popup x:Name="PART_Popup" AllowsTransparency="true" IsOpen="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" Placement="Bottom" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Focusable="false">
                    
<Microsoft_Windows_Themes:SystemDropShadowChrome MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{TemplateBinding ActualWidth}" x:Name="Shdw" Color="Transparent">
                        
<Border x:Name="DropDownBorder" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1">
                            
<ScrollViewer>
                                
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.DirectionalNavigation="Contained"/>
                            
</ScrollViewer>
                        
</Border>
                    
</Microsoft_Windows_Themes:SystemDropShadowChrome>
                
</Popup>
            
</Grid>
            
<ControlTemplate.Triggers>
                
<Trigger Property="HasItems" Value="false">
                    
<Setter Property="MinHeight" TargetName="DropDownBorder" Value="95"/>
                
</Trigger>
                
<Trigger Property="IsEnabled" Value="false">
                    
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                    
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                
</Trigger>
                
<Trigger Property="IsGrouping" Value="true">
                    
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                
</Trigger>
                
<Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true">
                    
<Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/>
                    
<Setter Property="Color" TargetName="Shdw" Value="#71000000"/>
                
</Trigger>
            
</ControlTemplate.Triggers>
        
</ControlTemplate>
        
<Style x:Key="LunaComboBoxStyle" TargetType="{x:Type ComboBox}">
            
<Setter Property="FocusVisualStyle" Value="{StaticResource ComboBoxFocusVisual}"/>
            
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
            
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
            
<Setter Property="BorderBrush" Value="{StaticResource ListBorder}"/>
            
<Setter Property="BorderThickness" Value="1"/>
            
<Setter Property="Padding" Value="1"/>
            
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
            
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
            
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
            
<Setter Property="VerticalContentAlignment" Value="Center"/>
            
<Setter Property="Template">
                
<Setter.Value>
                    
<ControlTemplate TargetType="{x:Type ComboBox}">
                        
<Grid SnapsToDevicePixels="true">
                            
<Border x:Name="Bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="1">
                                
<Grid Grid.IsSharedSizeScope="true">
                                    
<Grid.ColumnDefinitions>
                                        
<ColumnDefinition Width="1"/>
                                        
<ColumnDefinition Width="*"/>
                                        
<ColumnDefinition Width="Auto" SharedSizeGroup="ComboBoxButton"/>
                                    
</Grid.ColumnDefinitions>
                                    
<Border Margin="{TemplateBinding Padding}" x:Name="SelectedItemBorder" Grid.ColumnSpan="2"/>
                                    
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Grid.Column="1" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"/>
                                    
<ToggleButton Style="{StaticResource ComboBoxTransparentButtonStyle}" Grid.ColumnSpan="3" IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"/>
                                
</Grid>
                            
</Border>
                            
<Popup x:Name="PART_Popup" AllowsTransparency="true" IsOpen="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" Placement="Bottom" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Focusable="false">
                                
<Microsoft_Windows_Themes:SystemDropShadowChrome MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{TemplateBinding ActualWidth}" x:Name="Shdw" Color="Transparent">
                                    
<Border x:Name="DropDownBorder" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1">
                                        
<ScrollViewer>
                                            
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.DirectionalNavigation="Contained"/>
                                        
</ScrollViewer>
                                    
</Border>
                                
</Microsoft_Windows_Themes:SystemDropShadowChrome>
                            
</Popup>
                        
</Grid>
                        
<ControlTemplate.Triggers>
                            
<MultiTrigger>
                                
<MultiTrigger.Conditions>
                                    
<Condition Property="IsSelectionBoxHighlighted" Value="true"/>
                                    
<Condition Property="IsDropDownOpen" Value="false"/>
                                
</MultiTrigger.Conditions>
                                
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
                            
</MultiTrigger>
                            
<Trigger Property="IsSelectionBoxHighlighted" Value="true">
                                
<Setter Property="Background" TargetName="SelectedItemBorder" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
                            
</Trigger>
                            
<Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true">
                                
<Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/>
                                
<Setter Property="Color" TargetName="Shdw" Value="#71000000"/>
                            
</Trigger>
                            
<Trigger Property="HasItems" Value="false">
                                
<Setter Property="MinHeight" TargetName="DropDownBorder" Value="95"/>
                            
</Trigger>
                            
<Trigger Property="IsEnabled" Value="false">
                                
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                                
<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.Triggers>
                
<Trigger Property="IsEditable" Value="true">
                    
<Setter Property="IsTabStop" Value="false"/>
                    
<Setter Property="Padding" Value="0,1"/>
                    
<Setter Property="Template" Value="{StaticResource ComboBoxEditableTemplate}"/>
                
</Trigger>
            
</Style.Triggers>
        
</Style>
    
</Window.Resources>

    
<Grid x:Name="LayoutRoot">
        
<ComboBox Margin="159,143,352,0" Style="{DynamicResource LunaComboBoxStyle}" VerticalAlignment="Top" IsSynchronizedWithCurrentItem="True"/>
    
</Grid>
</Window>

posted on 2009-01-19 21:41  南柯之石  阅读(834)  评论(0编辑  收藏  举报

导航