Rudi Grobler

In the cloud

Building OpenPOS: Part 9 – Settings and Notifications

leave a comment »

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

First things first, lets 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

Building OpenPOS- Part 1 – Introduction
Building OpenPOS- Part 2 – Rapid prototype using SketchFlow
Building OpenPOS- Part 3 – Scaffolding and Navigation
Building OpenPOS- Part 4 – SalesModule (Part 1)
Building OpenPOS- Part 5 – SalesModule (Part 2)
Building OpenPOS- Part 6 – Make it look pretty…
Building OpenPOS- Part 7 – NoSQL, MSSQL, SQL CE-
Building OpenPOS- Part 8 – Windows 7 love

And you can download ALL the source from CodePlex here

About these ads

Written by rudigrobler

September 27, 2011 at 6:10 pm

Posted in Uncategorized

Tagged with

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: