Click here to Skip to main content
15,886,799 members
Articles / Desktop Programming / WPF

Presentation Model (MVVM) Good Practices

Rate me:
Please Sign up or sign in to vote.
4.81/5 (13 votes)
11 May 2010CPOL16 min read 67.9K   944   76  
Showing some good practices that can be applied to the Presentation Model/MVVM pattern.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PresentationModelBase;
using Microsoft.Win32;

namespace App.Configuration.Wpf
{
    class WpfDialogSystem : IDialogSystem
    {
        #region IDialogServicesProvider Members

        public QuestionResult AskQuestion(string question)
        {
            return AskQuestion(question, "Question");
        }

        public QuestionResult AskQuestion(string question, string title)
        {
            var result = System.Windows.MessageBox.Show(question, title, System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxImage.Question);
            switch (result)
            {
                case System.Windows.MessageBoxResult.Yes:
                    return QuestionResult.Yes;
                default:
                    return QuestionResult.No;
            }
        }

        public System.IO.FileInfo ChooseFile(string title, string filter)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Title = title;
            dialog.Filter = filter;
            dialog.ShowDialog();
            if (dialog.FileName != null && dialog.FileName.Trim() != string.Empty)
                return new System.IO.FileInfo(dialog.FileName);
            return null;
        }

        public System.IO.FileInfo ChooseImage()
        {
            return ChooseImage("");
        }

        public System.IO.FileInfo ChooseImage(string title)
        {
            return ChooseFile(title, "Image Files (*.bmp, *.jpg, *.jpeg, *.png)|*.bmp;*.jpg;*.jpeg;*.png");
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Brazil Brazil
Software developer specialized in the .NET framework

Comments and Discussions