WPF Cursor

Mouse.OverrideCursor = Cursors.Wait; 
try 
{ 
   

} 
finally 
{ 
   
Mouse.OverrideCursor = null; 
} 

public class OverrideCursor : IDisposable 
{ 
 
 
public OverrideCursor(Cursor changeToCursor) 
 
{ 
   
Mouse.OverrideCursor = changeToCursor; 
 
} 
 
 
#region IDisposable Members 
 
 
public void Dispose() 
 
{ 
   
Mouse.OverrideCursor = null; 
 
} 
 
 
#endregion 
} 

OR

 

public class OverrideCursor : IDisposable 
{ 
 
static Stack<Cursor> s_Stack = new Stack<Cursor>(); 
 
 
public OverrideCursor(Cursor changeToCursor) 
 
{ 
    s_Stack
.Push(changeToCursor); 
 
   
if (Mouse.OverrideCursor != changeToCursor) 
     
Mouse.OverrideCursor = changeToCursor; 
 
} 
 
 
public void Dispose() 
 
{ 
    s_Stack
.Pop(); 
 
   
Cursor cursor = s_Stack.Count > 0 ? s_Stack.Peek() : null; 
 
   
if (cursor != Mouse.OverrideCursor) 
     
Mouse.OverrideCursor = cursor; 
 
} 
 
} 

using (OverrideCursor cursor = new OverrideCursor(Cursors.Wait)) 
{ 
 
// Do work... 
} 

 

 

posted @ 2011-12-12 08:55  zhh  阅读(1246)  评论(0编辑  收藏  举报