Click here to Skip to main content
12,822,497 members (47,366 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 16 Apr 2009

Silverlight OverrideCursor

, 16 Apr 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
One of the really great things you can do with WPF is use Mouse.OverrideCursor to set the cursor for the entire application.

One of the really great things you can do with WPF is use Mouse.OverrideCursor to set the cursor for the entire application. This is useful, for instance, if you want your application to perform a lengthy operation, and have the cursor change to a wait cursor, for the duration of the operation. You'd normally do this like:

public void DoAReallyLongOperation()
  Cursor savedCursor = Mouse.OverrideCursor;
    Mouse.OverrideCursor = savedCursor

So far, so good. Now, of course, you're going to run off to your Silverlight applications and do exactly the same for your lengthy operations, aren't you? After all, Silverlight is a lightweight version of WPF, so surely this will be there for you to use.

Well no. Silverlight doesn't support the OverrideCursor, but adding it shouldn't be too hard, should it? Well, it turns out that adding the OverrideCursor isn't as easy as you'd think it would be. If you change the cursor on your page to a wait cursor, for instance, it will still be an IBeam when you move over a text box. This means that your code needs to traverse the visual tree looking for all of the child elements, and setting the cursor to the new cursor.

Edit: Since I posted this earlier today, an edge case was suggested that needed addressing. Basically, the code needs to be able to reset the text boxes back to the IBeam assuming that the OverrideCursor is set back.

The following class provides an attached property that should help greatly with this:

/// <span class="code-SummaryComment"><summary>


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Pete O'Hanlon
United Kingdom United Kingdom
A developer for over 30 years, I've been lucky enough to write articles and applications for Code Project as well as the Intel Ultimate Coder - Going Perceptual challenge. I live in the North East of England with 2 wonderful daughters and a wonderful wife.

I am not the Stig, but I do wish I had Lotus Tuned Suspension.

You may also be interested in...

Comments and Discussions

QuestionWhy change cursor? Pin
zlezj16-Apr-09 10:34
memberzlezj16-Apr-09 10:34 
AnswerRe: Why change cursor? Pin
Pete O'Hanlon16-Apr-09 10:59
mvpPete O'Hanlon16-Apr-09 10:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 16 Apr 2009
Article Copyright 2009 by Pete O'Hanlon
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid