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

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

Image.xaml
<canvas x:name="LayoutRoot">
    <img x:name="imgLogo1" source="Image/logo1.jpg" canvas.top="60" canvas.left="100"         canvas.zindex="1" mouseleave="imgLogo1_MouseLeave" mouseenter="imgLogo1_MouseEnter"         cursor="Hand">
        <image.rendertransform>
            <scaletransform x:name="LogoScale" centery="96"centerx="90">
            </scaletransform>
        </image.rendertransform>
    </img>
</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();
}

private void imgLogo1_MouseLeave(object sender, MouseEventArgs e)
{
    scaleDirection = ScaleDirection.Up;
    timer.Start();
}

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