如果使用自定义光标,Silverlight鼠标事件将停止工作

时间:2012-03-16 09:47:52

标签: c# silverlight user-controls cursor

我有一个silverlight应用程序,我使用以下代码用csuomt替换了鼠标光标:

UserControl:CustomC.xaml

<UserControl...>
    <Canvas>
    <Image x:Name="EGCursor" Visibility="Collapsed"></Image>
    </Canvas>
</UserControl>

UserControl:CustomC.xaml.cs

public void SetSource(string resource)
{
    EGCursor.Source = new BitmapImage(new Uri(resource, UriKind.Relative));
    EGCursor.Stretch = Stretch.None;
}
    public void MoveTo(Point pt)
{
    EGCursor.Visibility = Visibility.Visible;
    EGCursor.SetValue(Canvas.LeftProperty, pt.X - 13);
    MyCursor.SetValue(Canvas.TopProperty, pt.Y - 12);
}

MainWindow.xaml

<UserControl x:Class="SL.MainPage"... Cursor="None">
...
</UserControl>

MainWindow.xaml.cs

MainWindow()
{
CustomC = new CustomC();
CustomC.SetSource("GlowingCur.png");
LayoutRoot.Children.Add(CustomC);
}

void MainPage_MouseMove(object sender, MouseEventArgs e)
{
    CustomC.MoveTo(e.GetPosition(null));
}

在执行上述自定义光标时,我的silverlight MouseLeaveMouseClick等上的点击事件都将停止工作。如何更正此行为以便仅替换鼠标光标并且已编码的其他事件的工作方式相同?

1 个答案:

答案 0 :(得分:0)

尝试在自定义光标控件上将IsHitTestVisible设置为false:

CustomC = new CustomC();
SutomC.IsHitTestVisible = false;
CustomC.SetSource("GlowingCur.png");
LayoutRoot.Children.Add(CustomC);