<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,如需转载请自行联系原作者