zoukankan      html  css  js  c++  java
  • [Windows8开发] Button 默认样式

      1 <!-- Default style for Windows.UI.Xaml.Controls.Button -->
      2 <Style TargetType="Button">
      3     <Setter Property="Background" Value="{StaticResource ButtonBackgroundThemeBrush}" />
      4     <Setter Property="Foreground" Value="{StaticResource ButtonForegroundThemeBrush}"/>
      5     <Setter Property="BorderBrush" Value="{StaticResource ButtonBorderThemeBrush}" />
      6     <Setter Property="BorderThickness" Value="{StaticResource ButtonBorderThemeThickness}" />
      7     <Setter Property="Padding" Value="12,4,12,4" />
      8     <Setter Property="HorizontalAlignment" Value="Left" />
      9     <Setter Property="VerticalAlignment" Value="Center" />
     10     <Setter Property="FontFamily" Value="{StaticResource ContentControlThemeFontFamily}" />
     11     <Setter Property="FontWeight" Value="SemiBold" />
     12     <Setter Property="FontSize" Value="{StaticResource ControlContentThemeFontSize}" />
     13     <Setter Property="Template">
     14         <Setter.Value>
     15             <ControlTemplate TargetType="Button">
     16                 <Grid>
     17                     <VisualStateManager.VisualStateGroups>
     18                         <VisualStateGroup x:Name="CommonStates">
     19                             <VisualState x:Name="Normal" />
     20                             <VisualState x:Name="PointerOver">
     21                                 <Storyboard>
     22                                     <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border"
     23                                                                    Storyboard.TargetProperty="Background">
     24                                         <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonPointerOverBackgroundThemeBrush}" />
     25                                     </ObjectAnimationUsingKeyFrames>
     26                                     <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
     27                                                                    Storyboard.TargetProperty="Foreground">
     28                                         <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonPointerOverForegroundThemeBrush}" />
     29                                     </ObjectAnimationUsingKeyFrames>
     30                                 </Storyboard>
     31                             </VisualState>
     32                             <VisualState x:Name="Pressed">
     33                                 <Storyboard>
     34                                     <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border"
     35                                                                    Storyboard.TargetProperty="Background">
     36                                         <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonPressedBackgroundThemeBrush}" />
     37                                     </ObjectAnimationUsingKeyFrames>
     38                                     <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
     39                                                                    Storyboard.TargetProperty="Foreground">
     40                                         <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonPressedForegroundThemeBrush}" />
     41                                     </ObjectAnimationUsingKeyFrames>
     42                                 </Storyboard>
     43                             </VisualState>
     44                             <VisualState x:Name="Disabled">
     45                                 <Storyboard>
     46                                     <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border"
     47                                                                    Storyboard.TargetProperty="Background">
     48                                         <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonDisabledBackgroundThemeBrush}" />
     49                                     </ObjectAnimationUsingKeyFrames>
     50                                     <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border"
     51                                                                    Storyboard.TargetProperty="BorderBrush">
     52                                         <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonDisabledBorderThemeBrush}" />
     53                                     </ObjectAnimationUsingKeyFrames>
     54                                     <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
     55                                                                    Storyboard.TargetProperty="Foreground">
     56                                         <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonDisabledForegroundThemeBrush}" />
     57                                     </ObjectAnimationUsingKeyFrames>
     58                                 </Storyboard>
     59                             </VisualState>
     60                         </VisualStateGroup>
     61                         <VisualStateGroup x:Name="FocusStates">
     62                             <VisualState x:Name="Focused">
     63                                 <Storyboard>
     64                                     <DoubleAnimation Storyboard.TargetName="FocusVisualWhite"
     65                                                      Storyboard.TargetProperty="Opacity"
     66                                                      To="1"
     67                                                      Duration="0" />
     68                                     <DoubleAnimation Storyboard.TargetName="FocusVisualBlack"
     69                                                      Storyboard.TargetProperty="Opacity"
     70                                                      To="1"
     71                                                      Duration="0" />
     72                                 </Storyboard>
     73                             </VisualState>
     74                             <VisualState x:Name="Unfocused" />
     75                             <VisualState x:Name="PointerFocused" />
     76                         </VisualStateGroup>
     77                     </VisualStateManager.VisualStateGroups>
     78                     <Border x:Name="Border"
     79                             Background="{TemplateBinding Background}"
     80                             BorderBrush="{TemplateBinding BorderBrush}"
     81                             BorderThickness="{TemplateBinding BorderThickness}"
     82                             Margin="3">
     83                         <ContentPresenter x:Name="ContentPresenter"
     84                                           Content="{TemplateBinding Content}"
     85                                           ContentTransitions="{TemplateBinding ContentTransitions}"
     86                                           ContentTemplate="{TemplateBinding ContentTemplate}"
     87                                           Margin="{TemplateBinding Padding}"
     88                                           HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
     89                                           VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
     90                     </Border>
     91                     <Rectangle x:Name="FocusVisualWhite"
     92                                IsHitTestVisible="False"
     93                                Stroke="{StaticResource FocusVisualWhiteStrokeThemeBrush}"
     94                                StrokeEndLineCap="Square"
     95                                StrokeDashArray="1,1"
     96                                Opacity="0"
     97                                StrokeDashOffset="1.5" />
     98                     <Rectangle x:Name="FocusVisualBlack"
     99                                IsHitTestVisible="False"
    100                                Stroke="{StaticResource FocusVisualBlackStrokeThemeBrush}"
    101                                StrokeEndLineCap="Square"
    102                                StrokeDashArray="1,1"
    103                                Opacity="0"
    104                                StrokeDashOffset="0.5" />
    105                 </Grid>
    106             </ControlTemplate>
    107         </Setter.Value>
    108     </Setter>
    109 </Style>

    转自MSDN http://msdn.microsoft.com/zh-cn/library/windows/apps/xaml/jj709909.aspx 

    这样可以自定义Button。StandardStyle.xaml里面没有。

    当然,自定义样式之后(x:Key="****")如果运行时发现找不到相关Name/Key,这时候必须把<Page.Resource>放在引用该代码的前面。

  • 相关阅读:
    typescript
    js-解决安卓手机软键盘弹出后,固定定位布局被顶上移问题
    vue
    js
    Object.assgin基本知识与相关深浅拷贝
    js-工具方法(持续更新)
    vue
    vue
    git
    css
  • 原文地址:https://www.cnblogs.com/zetianchiang/p/2746839.html
Copyright © 2011-2022 走看看