大家帮我实现一个功能!

vincevincevincevince 2010-04-13 09:03:27
我想用silverlight实现一个按钮背景,按钮背景有三种状态,这三个状态是三张图片。鼠标正常,经过,点击时三张图片进行切换。请赐教!有实例的更好。QQ:454206743
...全文
198 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
imkfdcw 2010-05-04
  • 打赏
  • 举报
回复
最直接的办法就是按钮的mousemove(鼠标移动) MouseLeave(鼠标移开) mouseleftbuttondown(鼠标左键点下时) 这三个件事 通过这三个事件,你在后台设置button.background的填充对象,可以是单色,
可以是图片,也可以是渐变,这个就看自己需要什么就怎么定。试试看,一定行
lidongdong1986 2010-04-22
  • 打赏
  • 举报
回复
学习了~~
海涵德 2010-04-22
  • 打赏
  • 举报
回复
[Quote=引用楼主 vincevincevincevince 的回复:]
我想用silverlight实现一个按钮背景,按钮背景有三种状态,这三个状态是三张图片。鼠标正常,经过,点击时三张图片进行切换。请赐教!有实例的更好。QQ:454206743
[/Quote]
使用视觉状态管理Visual State Manager

<UserControl xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" x:Class="SL3madaming.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<UserControl.Resources >
<Style x:Key="buttonVSM2" TargetType="Button">
<!--定义样式-->
<Setter Property="Cursor" Value="hand"></Setter>
<Setter Property="Foreground" Value="White"></Setter>
<Setter Property="Template" >
<Setter.Value >
<!--定义控件模板-->
<ControlTemplate TargetType="Button">
<Grid>
<Image x:Name="image_normal" Source="/Resources/Assets/win7-2.jpg" Opacity="1" Stretch="Fill" ></Image>
<Image x:Name="image_mouse_over" Source="/Resources/Assets/win7-3.jpg" Opacity="0" Stretch="Fill" ></Image>
<Image x:Name="image_press" Source="/Resources/Assets/win7-4.jpg" Opacity="0" Stretch="Fill" ></Image>
<!--视觉管理组-->
<VisualStateManager.VisualStateGroups >
<VisualStateGroup >
<!--普通状态-->
<VisualState x:Name="Normal">
<Storyboard >
<DoubleAnimation Storyboard.TargetName="image_normal" Storyboard.TargetProperty="Opacity" To="1" ></DoubleAnimation>
<DoubleAnimation Storyboard.TargetName="image_mouse_over" Storyboard.TargetProperty="Opacity" To="0" ></DoubleAnimation>
<DoubleAnimation Storyboard.TargetName="image_press" Storyboard.TargetProperty="Opacity" To="0" ></DoubleAnimation>
</Storyboard>
</VisualState>

<!--鼠标经过-->
<VisualState x:Name="MouseOver">
<Storyboard >
<DoubleAnimation Storyboard.TargetName="image_normal" Storyboard.TargetProperty="Opacity" To="0" ></DoubleAnimation>
<DoubleAnimation Storyboard.TargetName="image_mouse_over" Storyboard.TargetProperty="Opacity" To="1" ></DoubleAnimation>
<DoubleAnimation Storyboard.TargetName="image_press" Storyboard.TargetProperty="Opacity" To="0" ></DoubleAnimation>
</Storyboard>
</VisualState>
<!--按下按钮-->
<VisualState x:Name="Pressed">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="image_normal" Storyboard.TargetProperty="Opacity" To="0" ></DoubleAnimation>
<DoubleAnimation Storyboard.TargetName="image_mouse_over" Storyboard.TargetProperty="Opacity" To="0" ></DoubleAnimation>
<DoubleAnimation Storyboard.TargetName="image_press" Storyboard.TargetProperty="Opacity" To="1" ></DoubleAnimation>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>

</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

</UserControl.Resources>
<Grid x:Name="LayoutRoot">
<StackPanel>
<Button x:Name="button_style" Width="50" Height="50" Margin="5" Style ="{StaticResource buttonVSM2}"></Button>
</StackPanel>

</Grid>
</UserControl>
ysx_001 2010-04-20
  • 打赏
  • 举报
回复
给你思路你自己写代码
1.重写Button的Content模板,里面可以放Object对象,想放图片就定义成image对象
2.重写Buttton的style动画面板Storybord,为三个状态添加鼠标状态
大体就这样。
你不贴代码出来我不会给你代码,我觉得这样是害人。你都没去思考余地。
你最好能从别的回复中组织点东西,然后自己写出来,成为完全自己的东西,我觉得这样比较好。
如果对我的思路有任何问题,欢迎随时提问,或你在写代码过程有任何疑问都可以问。
就是不可以自己什么都不做就要代码。
不错啊。。。呵呵
xjj571249 2010-04-20
  • 打赏
  • 举报
回复
学了了四楼的重写!!O(∩_∩)O~
daihua_1113 2010-04-20
  • 打赏
  • 举报
回复
呵呵 思路很好 顶个
chqa_2000 2010-04-20
  • 打赏
  • 举报
回复
用blend做很简单的 1分钟的事 写代码就麻烦了
直接创建3个state 绑定到对应的事件就可以了 官方的教程里就有
scdn8311 2010-04-16
  • 打赏
  • 举报
回复
不错,我也学习了.
  • 打赏
  • 举报
回复
我不知道怎么重写Button的Content模板,思路给我,也看不懂[Quote=引用 1 楼 timdavid 的回复:]
给你思路你自己写代码
1.重写Button的Content模板,里面可以放Object对象,想放图片就定义成image对象
2.重写Buttton的style动画面板Storybord,为三个状态添加鼠标状态
大体就这样。
你不贴代码出来我不会给你代码,我觉得这样是害人。你都没去思考余地。
你最好能从别的回复中组织点东西,然后自己写出来,成为完全自己的东西,我觉得这样比较好。
如果对我……
[/Quote]
TimDavid 2010-04-13
  • 打赏
  • 举报
回复
Ps:最好用Express Blend 3.0可以很快工作。
如果你理解上面的ControlTemplate和StroyBord之后用Express Blend最好,如果不懂建议在XAML里面写下。这样理解会更深刻。
TimDavid 2010-04-13
  • 打赏
  • 举报
回复
给你思路你自己写代码
1.重写Button的Content模板,里面可以放Object对象,想放图片就定义成image对象
2.重写Buttton的style动画面板Storybord,为三个状态添加鼠标状态
大体就这样。
你不贴代码出来我不会给你代码,我觉得这样是害人。你都没去思考余地。
你最好能从别的回复中组织点东西,然后自己写出来,成为完全自己的东西,我觉得这样比较好。
如果对我的思路有任何问题,欢迎随时提问,或你在写代码过程有任何疑问都可以问。
就是不可以自己什么都不做就要代码。
谢谢
TimDavid 2010-04-13
  • 打赏
  • 举报
回复
这个就是这样的
重写Button的COntent模板。

<Button>
<Button.Content>
<Image Source="路径"/>
</Button.Content>
</Button>

建议去看下一些Silverlight的书籍吧,和做点练习吧!

8,734

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧