style 样式中可否加入鼠标选中和离开的样式
<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>
<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>
[解决办法]
silverlight中没有wpf的trigger,但有替代方案
[解决办法]
使用视觉状态是正理,楼主可是试着去写写几个精美的Style.
如果你英文好可以去看看Delay的博客,他弄了个SilverlightDefaultStyleBrowser.exe专门查看DefaultStyle的.
可以通过SilverlightDefaultStyleBrowser.exe这个软件来学习如何设计精美UI。
[解决办法]
使用Blend可以很轻松实现你的要求。
参考:
Expression Blend实例中文教程系列
http://www.silverlightchina.net/html/learn/2010/0412/986.html
http://www.silverlightchina.net/html/learn/2010/0413/996.html
[解决办法]
使用VisualStateManager是正道
[解决办法]
VisualStateManager可以实现