Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

Building OpenPOS: Part 9 – Settings and Notifications

, 12 Aug 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
Building OpenPOS – Settings and Notifications

A common topic I see on StackOverflow is how I persist my window location in a WPF-friendly manner?

First things first, let's create some default values.

“The .NET Framework 2.0 allows you to create and access values that are persisted between application execution sessions.” – MSDN

Once we have some defaults, all we have to do is bind to them from our window! Sounds easy, huh?

First include the default namespace…

xmlns:local="clr-namespace:OpenPOS.Properties"

And then bind to them:

<Window x:Class="OpenPOS.Views.ShellView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:OpenPOS.Properties"
        Height="{Binding Source={x:Static local:Settings.Default}, 
		Path=Height, Mode=TwoWay}" 
        Width="{Binding Source={x:Static local:Settings.Default}, 
		Path=Width, Mode=TwoWay}"
        Left="{Binding Source={x:Static local:Settings.Default}, 
		Path=Left, Mode=TwoWay}" 
        Top="{Binding Source={x:Static local:Settings.Default}, Path=Top, Mode=TwoWay}"
        WindowState="{Binding Source={x:Static local:Settings.Default}, 
		Path=WindowState, Mode=TwoWay}">

</Window>

And that’s it!

Another common question I see often is how do I handle dialog boxes, etc.? The easy answer to this is just call MessageBox.Show, ShowDialog, etc.! And it will work in simple applications but what happens if you need to test this? Now you depend on a Dialog box that pops up or some user interaction! In OpenPOS, I create services for these kind of interactions! I created a VERY simple NotifyService for sending notifications:

public interface INotifyService
{
    void Notify(string message);
}

And this is how the notification looks:

BTW – this uses wpf-notifyicon (And here is a CodeProject article on how to use it).

For more information about OpenPOS

And you can download ALL the source from CodePlex here.

License

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

Share

About the Author

rudigrobler

South Africa South Africa
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.1411022.1 | Last Updated 12 Aug 2010
Article Copyright 2010 by rudigrobler
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid