码迷,mamicode.com
首页 > Web开发 > 详细

Silverlight 5 系列学习之二

时间:2014-07-02 20:05:14      阅读:266      评论:0      收藏:0      [点我收藏+]

标签:des   winform   http   width   os   art   

              昨天学习了一下Silverlight基础感觉也没有什么特别之处,不过圈里朋友劝我不要深入学习了,因为ms已不再爱他的这个孩子了,好吧那就把上些简单的东西稍微过一下吧,要不然公司有什么需求要改的小弟不会。单击事件,鼠标事件基本和Winform里的差不多,都是声明,注册。下面是个简单的图片浏览器如下代码:

              前台:

 

      <UserControl xmlns:my="clr-namespace:SilverlightApplication1"  x:Class="SilverlightApplication1.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:DesignHeight="400" d:DesignWidth="800">
    <Grid>

        <Canvas Background="#000000">
            <Canvas.Resources>
                <Storyboard x:Name="myStoryboard">
                    <DoubleAnimation
          Storyboard.TargetName="myTransform"
          Storyboard.TargetProperty="AngleY"
          From="0" To="180" Duration="0:0:5" RepeatBehavior="1x"/>
                    <DoubleAnimation
          Storyboard.TargetName="leftScaleTransform"
          Storyboard.TargetProperty="ScaleX"
          From="0" To="1" Duration="0:0:5" RepeatBehavior="1x"/>
                    <DoubleAnimation
          Storyboard.TargetName="leftScaleTransform"
          Storyboard.TargetProperty="ScaleY"
          From="0" To="1" Duration="0:0:5" RepeatBehavior="1x"/>
                    <DoubleAnimation
          Storyboard.TargetName="rightScaleTransform"
          Storyboard.TargetProperty="ScaleX"
          From="0" To="1" Duration="0:0:5" RepeatBehavior="1x"/>
                    <DoubleAnimation
          Storyboard.TargetName="rightScaleTransform"
          Storyboard.TargetProperty="ScaleY"
          From="0" To="1" Duration="0:0:5" RepeatBehavior="1x"/>
                </Storyboard>
            </Canvas.Resources>

            <Image Source="border.png" Canvas.Top="150" Canvas.Left="220"
               Width="356" Height="226"></Image>
            <Image x:Name="currentImg" Source="5.png" Width="340" Height="175"
               Canvas.Top="154" Canvas.Left="228">
                <Image.RenderTransform>
                    <TransformGroup>
                        <SkewTransform x:Name="myTransform" AngleX="0" AngleY="0"
                               CenterX="170" CenterY="87.5"></SkewTransform>
                    </TransformGroup>
                </Image.RenderTransform>
            </Image>

            <Image Source="border.png" Canvas.Top="180" Canvas.Left="20"
               Width="178" Height="113"></Image>
            <Image x:Name="leftImg" Source="4.png" Canvas.Top="182" Canvas.Left="24"
               Width="170" Height="87.5" Opacity="0.6"
               MouseEnter="OnMouseEnter" MouseLeave="OnMouseLeave"
               MouseLeftButtonDown="leftImg_MouseLeftButtonDown">
                <Image.RenderTransform>
                    <ScaleTransform x:Name="leftScaleTransform" ScaleX="1" ScaleY="1"
                            CenterX="85" CenterY="34"></ScaleTransform>
                </Image.RenderTransform>
            </Image>

            <Image Source="border.png" Canvas.Top="180" Canvas.Left="600"
               Width="178" Height="113"></Image>
            <Image x:Name="rightImg" Source="6.png" Canvas.Top="182" Canvas.Left="604"
               Width="170" Height="87.5" Opacity="0.6"
               MouseEnter="OnMouseEnter" MouseLeave="OnMouseLeave"
               MouseLeftButtonDown="rightImg_MouseLeftButtonDown">
                <Image.RenderTransform>
                    <ScaleTransform x:Name="rightScaleTransform" ScaleX="1" ScaleY="1"
                            CenterX="85" CenterY="34"></ScaleTransform>
                </Image.RenderTransform>
            </Image>
        </Canvas>
    </Grid>
        
</UserControl>

 

后台代码:

 private void OnMouseEnter(object sender, MouseEventArgs e)
        {
            Image img = sender as Image;
            img.Opacity = 1.0;
        }

        private void OnMouseLeave(object sender, MouseEventArgs e)
        {
            Image img = sender as Image;
            img.Opacity = 0.6;
        }
        private int index = 5;
        private int MIN = 1;
        private int MAX = 8;
        private void leftImg_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            index = index == MIN ? MAX : index - 1;
            Play();

        }

        private void rightImg_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            index = index == MAX ? MIN : index + 1;
            Play();

        }

        void Play()
        {


            int left = index == MIN ? MAX : index - 1;


            int right = index == MAX ? MIN : index + 1;

        }
 

 

               出来的效果如下:bubuko.com,布布扣

 

 

 

 

 

 

 

 

 

Silverlight 5 系列学习之二,布布扣,bubuko.com

Silverlight 5 系列学习之二

标签:des   winform   http   width   os   art   

原文地址:http://www.cnblogs.com/haofaner/p/3819574.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!