WP之Button按下时切换过渡效果图片
2014-03-28 13:43
169 查看
做项目时遇到个功能,button按下时(按下未松手时)要切换到相应的效果过渡图。
解决方案
1.在设计器里右键Button,选择“编辑模板”->“编辑副本”.然后VS会自动在xaml文件头部加上button的样式定义
2.找到 <span style="color:#ff0000;"><VisualState x:Name="Pressed">.... </VisualState></VisualStateGroup>
就是button按下时的样式切换。默认前景色替背景色,我们就是要将这个默认修改成我们的效果。
解决方案
1.在设计器里右键Button,选择“编辑模板”->“编辑副本”.然后VS会自动在xaml文件头部加上button的样式定义
<Style x:Key="ButtonStyle1" TargetType="Button"> <Setter Property="Background"> <Setter.Value> <ImageBrush ImageSource="/XXX/原来的图片.png"></ImageBrush> </Setter.Value> </Setter> <Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}"/> <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/> <Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/> <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}"/> <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMedium}"/> <Setter Property="Padding" Value="10,5,10,6"/> <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"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer"> <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneButtonBasePressedForegroundBrush}"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground"> <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneAccentBrush}"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </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" Margin="{StaticResource PhoneTouchTargetOverhang}"> <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>
2.找到 <span style="color:#ff0000;"><VisualState x:Name="Pressed">.... </VisualState></VisualStateGroup>
就是button按下时的样式切换。默认前景色替背景色,我们就是要将这个默认修改成我们的效果。
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground"> <DiscreteObjectKeyFrame KeyTime="0"> <DiscreteObjectKeyFrame.Value> <ImageBrush ImageSource="/XX/过渡图片.png/> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames>
相关文章推荐
- JS由左向右的图片渐变过渡切换效果
- Android 笔记:ImageButton单击切换按钮图片效果的实现(转)
- 图片自动切换(没有过渡效果)
- 一款在论坛上看到的JS封装的随机过渡方式的图片切换效果
- 图片切换效果(有过渡效果,不抖动)
- 图片切换特过渡效果
- wp———图片切换效果
- 利用css3+js实现简单带立体过渡效果的图片切换(chrome浏览器)
- Android ImageButton单击切换按钮图片效果
- Button按钮点击图片切换效果
- 使用TtransitionDrawable来实现图片颜色渐变过渡或者实现button的背景颜色渐变,很漂亮的效果
- jQuery的动画效果以及图片切换实例
- javascript设计模式实践之迭代器--具有百叶窗切换图片效果的JQuery插件(一)
- 原生js实现图片层叠轮播切换效果
- JQuery页面图片切换和新闻列表滚动效果的具体实现
- 自制图片过渡效果(共享)
- 拉勾网图片切换效果
- 仿土豆首页图片切换效果
- .net中如何生成Flash式的图片切换效果
- 带倒影的图片切换效果