[ACCEPTED]-WPF Notifications-wpf

Accepted answer
Score: 13

Your question is a little vague, in that 62 with WPF, your options here are really only 61 limited by your imagination.

Here are some 60 options:

This is the simplest option - if 59 you want to notify your user with a simple 58 message that he must acknowledge to continue, then 57 just show a message in a MessageBox.

Roll Your Own Dialog
If MessageBox 56 doesn't quite do it, and you want to show 55 more or different kinds of information, then 54 you can simply create a new Window, and 53 open it with the ShowDialog() method, forcing the user 52 to close it (acknowledge it) before proceeding.

If 51 you simply want to convey information, you 50 can just add a StatusBar to the bottom of your dialog. I've 49 linked to a nice example from fellow SO'er 48 Kent Boogaart. Note that you aren't limited to just 47 text in a StatusBar - you can add any UIElement 46 to it, so you could have images, progressbars, whatever.

Some Other Panel
You 45 could also have another panel of some sort 44 (using your example, a StackPanel or something 43 at the top of your application) that has 42 Visibility set to Collapsed unless it is 41 needed. You could also have, for example, a 40 Border with some content in it, that shows 39 up in front of the rest of the UIElements 38 in your dialog. You can use a PopUp control.

If 37 you go the "extra panel" route 36 (which perhaps sounds most in line with 35 what you are asking), then it may be nice 34 to do some tricks with animations to add 33 just a little flash to your app. Stuff 32 like sliding the panel into place, or animating 31 the opacity, etc. If you are putting the 30 information over the rest of your window 29 content, you can also play with the Opacity 28 to make the panel semi-transparent - dark 27 enough to see and read, but also allowing 26 the user to see a little bit of the window 25 behind it.

Here's a very basic example of 24 what I mean. I'll leave it as an exercise 23 for the user to add any formatting, slick 22 animations, handle multiple messages, etc.

<Window ...>
    <Grid x:Name="gridMainLayout">
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />

        <StackPanel x:Name="stackNotificationArea"

            <TextBlock x:Name="txtMessage"
                       Text="{Binding NotificationMessage}" />
            <Button x:Name="btnAcknowledge"
                    Content="Acknowledge" />

        <!-- Rest of your window goes here -->
        <Grid x:Name="gridContent"

              <!-- Content of window -->



In 21 the above example, I assume that there is 20 a property called NotificationMessage that 19 returns the latest notification message. You 18 could hard-code this in text, or whatever. It 17 would probably be best to bind the Visibility 16 of the StackPanel as well, based on if there 15 were any notifications. In any case, you 14 will have to toggle the StackPanel to Visible 13 as needed. Setting it to Visible will automatically 12 move the content of your window down, as 11 you described.

Be sure to set Visibility 10 to Collapsed when the message is acknowledged. If 9 you set it to Hidden, the StackPanel will 8 not be shown, but the real estate will still 7 be held for it (i.e. there will be a blank 6 space at the top of your application).

Of 5 course, you can be as fancy as you need 4 to be here - you could have a small listbox 3 with all the messages, or a couple of buttons 2 to scroll through messages, or a button 1 to launch a window with all messages, or...

More Related questions