적응이 되어가고 있는건지..
소스 따라하기 많이 버겁진 않쿠나.. ㅠ.ㅠ
<UserControl x:Class="mouseTracker.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<UserControl.Resources>
<!--눈돌아가는 스토리보드-->
<Storyboard x:Name="eyeMove" RepeatBehavior="Forever">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="359.579"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<!--달걀이동 스토리보드-->
<Storyboard x:Name="ghostMove">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="grid" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="63" x:Name="moveX"/> <!--X좌표 처리를 위해 Name 지어줌-->
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="grid" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="-26" x:Name="moveY"/> <!--Y좌표 처리를 위해 Name 지어줌-->
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<Grid Height="93" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Width="72" RenderTransformOrigin="0.5,0.5" x:Name="grid">
<Grid.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Grid.RenderTransform>
<Ellipse Height="18" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Bottom" Opacity="0.5" Fill="#FFEFF3C1" Stroke="#FF000000" StrokeThickness="0"/>
<Ellipse HorizontalAlignment="Stretch" Margin="0,0,0,9" VerticalAlignment="Stretch" Opacity="1" Fill="#FFE7E7E7" Stroke="#FF000000" StrokeThickness="0"/>
<Ellipse Height="26" HorizontalAlignment="Stretch" Margin="13,19,10,0" VerticalAlignment="Top" Fill="#FFFFFFFF" Stroke="#FF000000" StrokeThickness="0"/>
<Ellipse Height="26" HorizontalAlignment="Stretch" Margin="32,19,28,0" x:Name="ellipse" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Fill="#FFF90909" Stroke="#FF000000" StrokeThickness="0">
<Ellipse.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Ellipse.RenderTransform>
</Ellipse>
</Grid>
</Grid>
</UserControl>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
//추가로 필요한 네임스페이스(DispatcherTimer)
using System.Windows.Threading;
namespace mouseTracker
{
public partial class Page : UserControl
{
private Point tmpMouse = new Point(0, 0);
private Point nowMouse = new Point(0, 0);
public Page()
{
InitializeComponent();
//화면에서 마우스 이동 이벤트
this.MouseMove += new MouseEventHandler(Page_MouseMove);
moveX.Value = 0;
moveY.Value = 0;
//타이머
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(100); // 0.1초
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
eyeMove.Begin(); //눈 돌아가는 스토리보드 시작
}
private void timer_Tick(object sender, EventArgs e)
{
if (tmpMouse != nowMouse)
{
moveX.Value = nowMouse.X - (double)LayoutRoot.GetValue(Canvas.LeftProperty);
moveY.Value = nowMouse.Y - (double)LayoutRoot.GetValue(Canvas.TopProperty);
ghostMove.Begin();
tmpMouse = nowMouse;
}
}
private void Page_MouseMove(object sender, MouseEventArgs e)
{
var pt = e.GetPosition(this);
}
}
'Dev > Silveright' 카테고리의 다른 글
[실버라이트] .xap 파일 404 오류 (0) | 2008.08.26 |
---|---|
[실버라이트] 동적 TextBlock 생성하기 (0) | 2008.08.21 |
실버라이트 - DispatcherTimer 이용한 타이머 만들기 (0) | 2008.08.07 |
실버라이트 - Silverlight Key Enumeration (0) | 2008.08.05 |
Silverlight 1.1에서 2 Beta1으로 변경된 내용 정리 (0) | 2008.07.31 |