Click here to Skip to main content
Click here to Skip to main content

WPF Loading Wait Adorner

, 10 Feb 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

Jeremy Hutchinson
Software Developer Winxnet
United States United States
No Biography provided
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
Questionwork 100% but i need help PinmemberMico Perez9-Jul-13 19:46 
AnswerRe: work 100% but i need help PinmemberJeremy Hutchinson10-Jul-13 5:48 
GeneralRe: work 100% but i need help PinmemberMico Perez10-Jul-13 16:47 
GeneralRe: work 100% but i need help PinmemberMico Perez11-Jul-13 1:23 
QuestionAwesome! - Instead of 100% Screen Coverage Pinmemberstan_mcginnis26-Oct-12 6:39 
AnswerRe: Awesome! - Instead of 100% Screen Coverage PinmemberJeremy Hutchinson26-Oct-12 6:58 
QuestionHow to make loading wait adorner visible while a window is created and showed? Pinmembermary4wpf3-Oct-12 7:23 
AnswerRe: How to make loading wait adorner visible while a window is created and showed? PinmemberJeremy Hutchinson4-Oct-12 8:43 
Suggestionabout the libraries PinmemberPinocs1-Jun-12 6:30 
GeneralRe: about the libraries PinmemberJeremy Hutchinson1-Jun-12 6:34 
QuestionIts not working with asynchronous call [modified] PinmemberMember 34620802-Mar-12 21:22 
AnswerRe: Its not working with asynchronous call PinmemberJeremy Hutchinson5-Mar-12 10:26 
QuestionDispatcherPriority.ContextIdle cause unnormal! Pinmemberwalker_ck18-Aug-11 23:36 
GeneralLoadingWait and BackgroundWorker Pinmemberlmhf00428-Sep-10 16:38 
GeneralRe: LoadingWait and BackgroundWorker PinmemberJeremy Hutchinson29-Sep-10 2:59 
GeneralRe: LoadingWait and BackgroundWorker PinmemberMember 173204230-May-11 8:25 
GeneralUsing this with a tab control interface PinmemberTimothy Lin Zheng Tian30-Jun-10 22:45 
GeneralRe: Using this with a tab control interface PinmemberJeremy Hutchinson1-Jul-10 3:30 
GeneralNice article PinmemberAshley Davis17-Feb-10 23:37 
GeneralRe: Nice article PinmemberJeremy Hutchinson18-Feb-10 5:02 
QuestionWhat a good combination PinmemberBill Seddon16-Feb-10 0:51 
GeneralCool PinmvpSacha Barber11-Feb-10 4:19 
GeneralRe: Cool PinmemberJeremy Hutchinson11-Feb-10 4:33 
GeneralRe: Cool PinmvpSacha Barber11-Feb-10 5:20 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.1411023.1 | Last Updated 10 Feb 2010
Article Copyright 2010 by Jeremy Hutchinson
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid