none
Silverlight mouse events stop working if custom cursor used

    Question

  • I have a silverlight application in which I replaced the Mouse Cursor with a csuomt using the following code:

    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));
        }
    On doing the above for a custom cursor, the click events on my silverlight `MouseLeave`, `MouseClick` etc. all stop working. How do I correct this behavior so that only the mouse cursor is replaced and other events that have been already coded work the same?
    Friday, March 16, 2012 5:59 AM

Answers