专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Silverlight

style 样式中可否加入鼠标选中和离开的样式解决思路

发布时间:2011-06-27 20:15:42 文章来源:www.iduyao.cn 采编人员:星星草
style 样式中可否加入鼠标选中和离开的样式
XML code

 <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 设置上鼠标点击后给图片加个小框,或更换一张图片 ,失去焦点后,去除小框.


------解决方案--------------------
EventTrigger
------解决方案--------------------
通过行为和事件触发控制就可以实现
------解决方案--------------------
探讨
XML code

<Style x:Name="MyPointStyle" TargetType="DeepProtoControls:MyPoint" >
<Setter Property="RenderTransformOrigin" Value="0.5,0.5" />
<Setter Property="AnchorPoint"……

------解决方案--------------------
VB.NET code

<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>
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: