2014-03-05 38 views
0

是否有可能从c#后面的代码中的按钮中删除突出显示样式?如何从按钮中删除突出显示样式

这是我的按钮声明:

var button = new Button() { Content = text }; 
button.HorizontalAlignment = HorizontalAlignment.Left; 
button.BorderThickness = new Thickness(0); 
TiltEffect.SetIsTiltEnabled(button, true); 
button.style = ???? 
+0

什么样的高光风格?你在谈论点击按钮时发生的效果吗? –

+0

我会从代码 –

+0

中的按钮删除压制的视觉风格是的..通过覆盖按钮的控制模板 –

回答

1

每个按钮连接到它,并不断模板有喜欢的多可视状态的模板压残疾人等

您需要用视觉玩一个按钮的状态,你可以在风格的帮助下做到这一点

只要看看下面的风格。

<Style x:Key="style_ColorButton" TargetType="Button"> 
     <Setter Property="Background" Value="Black"/> 
     <Setter Property="BorderBrush" Value="White"/> 
     <Setter Property="Foreground" Value="White"/> 
     <Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/> 
     <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}"/> 
     <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/> 
     <Setter Property="Padding" Value="10,3,10,5"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="Button"> 
        <Grid Background="Transparent"> 
         <VisualStateManager.VisualStateGroups> 
          <VisualStateGroup x:Name="CommonStates"> 
           <VisualState x:Name="Normal"/> 
           <VisualState x:Name="MouseOver"/> 
           <VisualState x:Name="Pressed"> 
           </VisualState> 
           <VisualState x:Name="Disabled"> 
            <Storyboard> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer"> 
              <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground"> 
              <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground"> 
              <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent"/> 
             </ObjectAnimationUsingKeyFrames> 
            </Storyboard> 
           </VisualState> 
          </VisualStateGroup> 
         </VisualStateManager.VisualStateGroups> 
         <Border x:Name="ButtonBackground" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="0"> 
          <ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/> 
         </Border> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

使用此按钮样式。

<Button Height="40" Width="40" BorderThickness="0" Name="btnAcceptCrop" Click="btnAcceptCrop_Click" Style="{StaticResource style_ColorButton}" Background="Black" ForeGround="White"/> 

设置样式代码

btnAcceptCrop.Style = (Style)App.Current.Resources["style_ColorButton"]; 

在你的页面在页面

声明一个风格下的所有空间声明

只是做一个标记

<phone:PhoneApplicationPage.Resources> 
</phone:PhoneApplicationPage.Resources> 

并在里面声明你的风格。

希望这会有所帮助。

相关问题