Click here to Skip to main content
Licence CPOL
First Posted 10 Feb 2010
Views 35,809
Downloads 2,719
Bookmarked 63 times

WPF Loading Wait Adorner

By | 10 Feb 2010 | Article
Easily add a "Loading" overlay that "grays out" the form and adds a circular progress bar to any form.

Introduction

First, let me give credit where credit is clearly due as I am standing on the shoulders of better developers with this one. It's basically a combination of two articles written by others to create something I've always wanted in my WPF toolkit.

The whole AdornedControl project which allows you to define your Adorners in XAML came from Ashley Davis. I'm fairly green when it comes to adorners, and could not have completed my article without his.

The other article I pulled from was Sacha Barber's circular progressbar article. I am not a designer by any stretch of the imagination, and wouldn't have known where to start on an animated circular progress bar.

Using the code

The first thing I did was put together a simple form with a button to simulate starting and stopping loading and a simple ListBox. Then, I wrapped the ListBox with an AdornedControl and created an AdornedControl.AdornerContent which contains the UserControl that will display when the adorner is visible.

<StackPanel>
    <Button Click="Button_Click">Start/Stop Waiting</Button>
    <ac:AdornedControl Name="LoadingAdorner">
        <ac:AdornedControl.AdornerContent>
            <local:LoadingWait></local:LoadingWait>
        </ac:AdornedControl.AdornerContent>
        <ListBox Name="ListBox1">
            <ListBoxItem>Item 1</ListBoxItem>
            <ListBoxItem>Item 2</ListBoxItem>
            <ListBoxItem>Item 3</ListBoxItem>
        </ListBox>
    </ac:AdornedControl>    
</StackPanel>

The Button_Click event calls a method that flips LoadingAdorner.IsAdornerVisible and ListBox1.IsEnabled. In production, those will be bound to the IsEnabled and IsBusy properties on the ViewModel.

private void StartStopWait()
{
    LoadingAdorner.IsAdornerVisible = !LoadingAdorner.IsAdornerVisible;
    ListBox1.IsEnabled = !ListBox1.IsEnabled;
}

<local:LoadingWait> is the UserControl that both "grays out" the adorned area and displays the ring of progress. This is essentially Sacha's code, I just added a brush to the UserControl to do the "graying", and added a brush as a resource so I could easily change the colors of all the dots at once.

Conclusion

I can now go through my existing application and add this little adornment around any area that takes more than an instant to load its data. All I'll have to do is paste the adornment code into the XAML, bind the IsAdornerVisible to an IsBusy property, and set the IsBusy property from code.

As you can see, I didn't add a lot to Ashley and Sacha's previous works, and I would like to thank them again.

History

  • Feb 10th 2010 - Article posted.

License

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

About the Author

Jeremy Hutchinson

Team Leader
Ability Resources
United States United States

Member

Follow on Twitter Follow on Twitter


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionIts not working with asynchronous call [modified] PinmemberMember 346208020:22 2 Mar '12  
AnswerRe: Its not working with asynchronous call PinmemberJeremy Hutchinson9:26 5 Mar '12  
QuestionDispatcherPriority.ContextIdle cause unnormal! Pinmemberwalker_ck22:36 18 Aug '11  
GeneralLoadingWait and BackgroundWorker Pinmemberlmhf00415:38 28 Sep '10  
GeneralRe: LoadingWait and BackgroundWorker PinmemberJeremy Hutchinson1:59 29 Sep '10  
GeneralRe: LoadingWait and BackgroundWorker PinmemberMember 17320427:25 30 May '11  
GeneralUsing this with a tab control interface PinmemberTimothy Lin Zheng Tian21:45 30 Jun '10  
GeneralRe: Using this with a tab control interface PinmemberJeremy Hutchinson2:30 1 Jul '10  
GeneralNice article PinmemberAshley Davis22:37 17 Feb '10  
GeneralRe: Nice article PinmemberJeremy Hutchinson4:02 18 Feb '10  
QuestionWhat a good combination PinmemberBill Seddon23:51 15 Feb '10  
GeneralCool PinmvpSacha Barber3:19 11 Feb '10  
GeneralRe: Cool PinmemberJeremy Hutchinson3:33 11 Feb '10  
GeneralRe: Cool PinmvpSacha Barber4:20 11 Feb '10  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web03 | 2.5.120517.1 | Last Updated 10 Feb 2010
Article Copyright 2010 by Jeremy Hutchinson
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid