WPF 鼠标移动到图片变大,移开还原,单击触发事件效果

<Grid>
         <Canvas x:Name= "LayoutRoot" >
             <Image Cursor= "Hand"  MouseLeftButtonDown= "imgLogo1_MouseLeftButtonDown"  MouseEnter= "imgLogo1_MouseEnter"
                    MouseLeave= "imgLogo1_MouseLeave"  Canvas.ZIndex= "1"  x:Name= "imgLogo1"  Canvas.Left= "100"
                    Canvas.Top= "60"  Height= "100"  Source= "Image/Picture.jpg" >
                 <Image.RenderTransform>
                     <ScaleTransform x:Name= "LogoScale"  CenterX= "90"  CenterY= "96" >
 
                     </ScaleTransform>
                 </Image.RenderTransform>
             </Image>
         </Canvas>
     </Grid>

  

public  partial  class  Window8 : Window
    {
        public  Window8()
        {
            InitializeComponent();
            timer = new  System.Windows.Threading.DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(50);
            timer.Tick += new  EventHandler(timer_Tick);
        }
 
        private  System.Windows.Threading.DispatcherTimer timer;
        private  ScaleDirection scaleDirection ;
       
 
        void  timer_Tick( object  sender, EventArgs e)
        {
            AdjustScale(scaleDirection, LogoScale);
        }
 
        void  AdjustScale(ScaleDirection scaleDirection, ScaleTransform scale)
        {
            if  (scaleDirection == ScaleDirection.Down)
            {
                if  (scale.ScaleX < 1.3)
                {
                    scale.ScaleX += 0.05; scale.ScaleY += 0.05;
                }
                else
                    timer.Stop();
            }
            else
            {
                if  (scale.ScaleX > 1.0)
                {
                    scale.ScaleX -= 0.05;
                    scale.ScaleY -= 0.05;
                }
                else
                    timer.Stop();
            }
        }
 
        enum  ScaleDirection
        {
            Up,
            Down
        }
 
        private  void  imgLogo1_MouseEnter( object  sender, MouseEventArgs e)
        {
            scaleDirection = ScaleDirection.Down;
            timer.Start();
        }
 
        private  void  imgLogo1_MouseLeave( object  sender, MouseEventArgs e)
        {
            scaleDirection = ScaleDirection.Up;
            timer.Start();
        }
 
        private  void  imgLogo1_MouseLeftButtonDown( object  sender, MouseButtonEventArgs e)
        {
            MessageBox.Show( "test" );
        }
    }

原文:http://www.csharpwin.com/dotnetspace/10339r6936.shtml

 

编辑器加载中...



本文转自Work Hard Work Smart博客园博客,原文链接:http://www.cnblogs.com/linlf03/archive/2011/08/23/2150559.html,如需转载请自行联系原作者

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值