style 样式中可否加入鼠标选中和离开的样式

zywhao 2010-04-22 09:01:59

<Style x:Name="MyPointStyle" TargetType="DeepProtoControls:MyPoint" >
<Setter Property="RenderTransformOrigin" Value="0.5,0.5" />
<Setter Property="AnchorPoint" Value="0.5,0.5" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DeepProtoControls:MyPoint" >
<Grid x:Name="_LayoutRoot">
<Image x:Name="_Image" Stretch="UniformToFill" Height="24" Width="24" Canvas.ZIndex="2" Source="Resources/red.PNG" ToolTipService.Placement="Top">
<Image.RenderTransform>
<RotateTransform x:Name="shipTransform" CenterX="12" CenterY="12"/>
</Image.RenderTransform>

</Image>

</Grid>

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


如何在给 image 设置上鼠标点击后给图片加个小框,或更换一张图片 ,失去焦点后,去除小框.
...全文
235 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
hsy36000 2010-07-19
  • 打赏
  • 举报
回复
6楼正解。相当犀利啊。
xingjunli 2010-04-29
  • 打赏
  • 举报
回复
使用VisualStateManager是正道
xingjunli 2010-04-29
  • 打赏
  • 举报
回复
使用VisualStateManager是正道
xingjunli 2010-04-29
  • 打赏
  • 举报
回复
使用VisualStateManager是正道
fenglm999 2010-04-29
  • 打赏
  • 举报
回复
VisualStateManager可以实现
jv9 2010-04-29
  • 打赏
  • 举报
回复
使用Blend可以很轻松实现你的要求。

参考:

Expression Blend实例中文教程系列

http://www.silverlightchina.net/html/learn/2010/0412/986.html

http://www.silverlightchina.net/html/learn/2010/0413/996.html
mengKzhaoyun 2010-04-28
  • 打赏
  • 举报
回复
使用视觉状态是正理,楼主可是试着去写写几个精美的Style.
如果你英文好可以去看看Delay的博客,他弄了个SilverlightDefaultStyleBrowser.exe专门查看DefaultStyle的.
可以通过SilverlightDefaultStyleBrowser.exe这个软件来学习如何设计精美UI。
ck436 2010-04-28
  • 打赏
  • 举报
回复
silverlight中没有wpf的trigger,但有替代方案
seeyou1997 2010-04-22
  • 打赏
  • 举报
回复
EventTrigger
海涵德 2010-04-22
  • 打赏
  • 举报
回复

<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>
海涵德 2010-04-22
  • 打赏
  • 举报
回复
[Quote=引用楼主 zywhao 的回复:]
XML code

<Style x:Name="MyPointStyle" TargetType="DeepProtoControls:MyPoint" >
<Setter Property="RenderTransformOrigin" Value="0.5,0.5" />
<Setter Property="AnchorPoint"……
[/Quote]
可以,使用视觉状态。
http://topic.csdn.net/u/20100413/09/48eabcbd-b4ee-4303-999b-920672153322.html?13285
beniao277 2010-04-22
  • 打赏
  • 举报
回复
通过行为和事件触发控制就可以实现

8,744

社区成员

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

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