• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
jasmin_xm
博客园    首页    新随笔    联系   管理    订阅  订阅

Silverlight学习笔记(1)-3.0放大缩小

Image.xaml

<Canvas x:Name="LayoutRoot">
 <Image Cursor="Hand" MouseEnter="imgLogo1_MouseEnter"  Canvas.ZIndex="1" x:Name="imgLogo1" Canvas.Left="100"       Canvas.Top="60"  Source="Image/logo1.jpg">
  <Image.RenderTransform>
   <ScaleTransform x:Name="LogoScale" CenterX="90" CenterY="96"></ScaleTransform>
  </Image.RenderTransform>
 </Image>
</Canvas>
Image.xaml.cs

private System.Windows.Threading.DispatcherTimer timer;
private ScaleDirection scaleDirection ;

public Page()
{  

   InitializeComponent();
   timer = new System.Windows.Threading.DispatcherTimer();
   timer.Interval = TimeSpan.FromMilliseconds(50);
   timer.Tick += new EventHandler(timer_Tick);
}

 

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();
}


 

posted @ 2010-03-21 03:31  jasmin  阅读(365)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3