ComboBoxStyle和ToggleButton

<Style x:Key="ComboBoxStyle" TargetType="{x:Type ComboBox}">
   <Setter Property="FocusVisualStyle" Value="{StaticResource ComboBoxFocusVisual}"/>
   <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
   <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
   <Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/>
   <Setter Property="BorderThickness" Value="1"/>
   <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
   <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
   <Setter Property="Padding" Value="4,3"/>
   <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
   <Setter Property="ScrollViewer.PanningMode" Value="Both"/>
   <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
   <Setter Property="Template">
    <Setter.Value>
     <ControlTemplate 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>
       <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="CommonStates">
         <VisualState x:Name="Normal"/>
         <VisualState x:Name="MouseOver"/>
         <VisualState x:Name="Disabled"/>
        </VisualStateGroup>
        <VisualStateGroup x:Name="FocusStates">
         <VisualState x:Name="Unfocused"/>
         <VisualState x:Name="Focused"/>
         <VisualState x:Name="FocusedDropDown"/>
        </VisualStateGroup>
        <VisualStateGroup x:Name="EditStates">
         <VisualState x:Name="Editable"/>
         <VisualState x:Name="Uneditable"/>
        </VisualStateGroup>
        <VisualStateGroup x:Name="ValidationStates">
         <VisualState x:Name="Valid"/>
         <VisualState x:Name="InvalidFocused"/>
         <VisualState x:Name="InvalidUnfocused"/>
        </VisualStateGroup>
       </VisualStateManager.VisualStateGroups>
       <VisualStateManager.CustomVisualStateManager>
        <ei:ExtendedVisualStateManager/>
       </VisualStateManager.CustomVisualStateManager>
       <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">
        <Microsoft_Windows_Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=MainGrid}" OpacityMask="Black">
         <Border x:Name="DropDownBorder" BorderThickness="1" Background="#FF434343">
          <ScrollViewer x:Name="DropDownScrollViewer">
           <Grid RenderOptions.ClearTypeHint="Enabled">
            <Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
             <Rectangle x:Name="OpaqueRect" Height="{Binding ActualHeight, ElementName=DropDownBorder}" Width="{Binding ActualWidth, ElementName=DropDownBorder}" Fill="#FFC7C7C7"/>
            </Canvas>
            <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" OpacityMask="#FF777777"/>
           </Grid>
          </ScrollViewer>
         </Border>
        </Microsoft_Windows_Themes:SystemDropShadowChrome>
       </Popup>
       <ToggleButton Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{DynamicResource ToggleButtonStyle}" Background="#FF777777" BorderBrush="#FF434343" Width="Auto"/>
       <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}" OpacityMask="#FF777777"/>
      </Grid>
      <ControlTemplate.Triggers>
       <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="Height" TargetName="DropDownBorder" Value="95"/>
        <Setter Property="BorderBrush" TargetName="DropDownBorder" Value="#FF777777"/>
       </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">
        <Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}"/>
        <Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}"/>
       </Trigger>
      </ControlTemplate.Triggers>
     </ControlTemplate>
    </Setter.Value>
   </Setter>
   <Style.Triggers>
    <Trigger Property="IsEditable" Value="true">
     <Setter Property="BorderBrush" Value="{StaticResource TextBoxBorder}"/>
     <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
     <Setter Property="IsTabStop" Value="false"/>
     <Setter Property="Padding" Value="3"/>
     <Setter Property="Template" Value="{StaticResource ComboBoxEditableTemplate}"/>
    </Trigger>
   </Style.Triggers>
  </Style>
  <Style x:Key="ToggleButtonStyle" 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}">
      <Microsoft_Windows_Themes:ButtonChrome x:Name="Chrome" SnapsToDevicePixels="true" Background="#FF777777" BorderBrush="#FF777777" RenderMouseOver="False">
       <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="CommonStates">
         <VisualState x:Name="Normal"/>
         <VisualState x:Name="MouseOver"/>
         <VisualState x:Name="Pressed"/>
         <VisualState x:Name="Disabled"/>
        </VisualStateGroup>
       </VisualStateManager.VisualStateGroups>
       <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>
      </Microsoft_Windows_Themes:ButtonChrome>
      <ControlTemplate.Triggers>
       <Trigger Property="IsEnabled" Value="false">
        <Setter Property="Fill" TargetName="Arrow" Value="#AFAFAF"/>
       </Trigger>
       <Trigger Property="IsChecked" Value="False"/>
       <EventTrigger RoutedEvent="FrameworkElement.Loaded"/>
      </ControlTemplate.Triggers>
     </ControlTemplate>
    </Setter.Value>
   </Setter>
  </Style>

转载于:https://www.cnblogs.com/changbaishan/p/4645783.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值