会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
The Stars ...My Destination
adamxx
天下事,法无定法,然后知非法法之 世间人,尤了未了,何妨以不了了之
导航
博客园
首页
新随笔
联系
订阅
管理
公告
Silverlight 自定义光标 Custom Cursor
Posted on
2008-01-10 17:36
adamxx
阅读(
4365
) 评论(
3
)
收藏
举报
Silverlight 自定义光标 Custom Cursor
其实很简单,将在Load的时候将光标设置为none值,在前台随便画一个东西,鼠标移动的时候跟随就行
<
Rectangle
Width
="20"
Height
="20"
x:Name
="cursor"
>
<
Rectangle.Triggers
>
<
EventTrigger
RoutedEvent
="Canvas.Loaded"
>
<
BeginStoryboard
>
<
Storyboard
>
<
DoubleAnimation
Storyboard.TargetName
="rotate"
Storyboard.TargetProperty
="Angle"
By
="360"
Duration
="00:00:03"
RepeatBehavior
="Forever"
/>
</
Storyboard
>
</
BeginStoryboard
>
</
EventTrigger
>
</
Rectangle.Triggers
>
<
Rectangle.RenderTransform
>
<
RotateTransform
x:Name
="rotate"
CenterX
="10"
CenterY
="10"
/>
</
Rectangle.RenderTransform
>
<
Rectangle.Fill
>
<
LinearGradientBrush
>
<
GradientStop
Color
="White"
Offset
="0"
/>
<
GradientStop
Color
="Red"
Offset
=".5"
/>
<
GradientStop
Color
="Black"
Offset
="1"
/>
</
LinearGradientBrush
>
</
Rectangle.Fill
>
</
Rectangle
>
public
void
Page_Loaded(
object
o, EventArgs e)
{
//
Required to initialize variables
InitializeComponent();
this
.Cursor
=
Cursors.None;
}
public
void
OnMouseMove(
object
sender, MouseEventArgs e)
{
double
x
=
e.GetPosition(
this
).X;
double
y
=
e.GetPosition(
this
).Y;
if
(x
<=
20
||
x
>=
this
.Width
-
20
||
y
<=
20
||
y
>=
this
.Height
-
20
)
this
.cursor.Visibility
=
Visibility.Collapsed;
else
this
.cursor.Visibility
=
Visibility.Visible;
this
.cursor.SetValue
<
double
>
(Canvas.LeftProperty, x);
this
.cursor.SetValue
<
double
>
(Canvas.TopProperty, y);
}
刷新页面
返回顶部
博客园
© 2004-2025
浙公网安备 33010602011771号
浙ICP备2021040463号-3