大佬教程收集整理的这篇文章主要介绍了Silverlight 按钮MouseOver状态下 文字、图片、背景同时改变,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
Button 当MouSEOver时,其布局中的文字改变颜色,图片换图,背景色改变
例如:以下两张图片分别代表正常状态与鼠标滑过状态
按钮代码如下:
<Button Style="{Staticresource btnStylE}" Content="ABCDEFG" />
样式代码如下:
<Style x:Key="btnStyle" TargetType="Button"> <Setter Property="Padding" Value="1"/> <Setter Property="BorderThickness" Value="0"/> <Setter Property="BorderBrush" Value="Transparent"/> <Setter Property="BACkground" Value="#FF999900" /> <Setter Property="Foreground" Value="#FF3191c3"/> <Setter Property="FontSize" Value="16" /> <Setter Property="Width" Value="110" /> <Setter Property="Height" Value="70" /> <Setter Property="cursor" Value="Hand"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Grid> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Normal"/> <VisualState x:Name="MouSEOver"> <Storyboard> <ColorAnimationUsingKeyFrames Duration="1" Storyboard.TargetProperty="(Border.BACkground).(SolidColorBrush.Color)" Storyboard.TargetName="BACkground"> <EasingColorKeyFrame KeyTime="0" Value="#FF3191c3" /> </ColorAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames BeginTime="0" Storyboard.TargetName="icon" Storyboard.TargetProperty="(Image.sourcE)"> <DiscreteObjectKeyFrame KeyTime="0"> <DiscreteObjectKeyFrame.Value> <BitmapImage Urisource="images/ywbl_sel.png" /> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> <ColorAnimation Duration="0" To="#FFFFFF" Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="textBlock" /> </Storyboard> </VisualState> <VisualState x:Name="Pressed"> <Storyboard> </Storyboard> </VisualState> <VisualState x:Name="Disabled"> <Storyboard> <DoubleAnimation Duration="0" To=".55" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="DisabledVisualElement"/> </Storyboard> </VisualState> </VisualStateGroup> <VisualStateGroup x:Name="FocusStates"> <VisualState x:Name="Focused"> <Storyboard> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FocusVisualElement"/> </Storyboard> </VisualState> <VisualState x:Name="Unfocused"/> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Border x:Name="BACkground" Opacity="1" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" BACkground="{TemplateBinding BACkgrounD}" CornerRadius="0"> <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> <Grid.RowDeFinitions> <RowDeFinition Height="2*" /> <RowDeFinition Height="*" /> </Grid.RowDeFinitions> <Image x:Name="icon" Grid.Row="0" source="images/ywbl.png" Width="25" Height="25" HorizontalAlignment="Center" Margin="0 10 0 0"/> <TextBlock x:Name="textBlock" Grid.Row="1" Text="{TemplateBinding Content}" Margin="0 -5 0 0" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalAlignment="Center" /> </Grid> </Border> <Rectangle x:Name="DisabledVisualElement" Fill="#FFFFFFFF" IsHitTestVisible="false" Opacity="0" RadiusY="3" RadiusX="3"/> <Rectangle x:Name="FocusVisualElement" IsHitTestVisible="false" Margin="1" Opacity="0" RadiusY="2" RadiusX="2" stroke="#FF6DBDD1" strokeThickness="0"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>
===== 记录完毕, 为日后方便在项目使用====
以上是大佬教程为你收集整理的Silverlight 按钮MouseOver状态下 文字、图片、背景同时改变全部内容,希望文章能够帮你解决Silverlight 按钮MouseOver状态下 文字、图片、背景同时改变所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。