Click here to Skip to main content
15,885,366 members
Articles / Desktop Programming / WPF

Building WPF Applications with Self-Tracking Entity Generator - Project Setup

Rate me:
Please Sign up or sign in to vote.
4.80/5 (11 votes)
20 Feb 2012CPOL10 min read 75.3K   4.8K   54  
This article describes the project setup of building a WPF sample application with Self-Tracking Entity Generator for WPF/Silverlight.
using System;
using System.Windows;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Messaging;
using SchoolSample.Common;

namespace SchoolSample
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        #region "Private Data"
        private Home homeScreen;
        private CoursePage coursePage;
        private InstructorPage instructorPage;
        private StudentPage studentPage;
        #endregion "Private Data"

        #region "Constructor"

        public MainWindow()
        {
            InitializeComponent();

            // register for RaiseErrorMessage
            AppMessages.RaiseErrorMessage.Register(this, OnRaiseErrorMessage);
            // register for PleaseConfirmMessage
            AppMessages.PleaseConfirmMessage.Register(this, OnPleaseConfirmMessage);
            // register for StatusUpdateMessage
            AppMessages.StatusUpdateMessage.Register(this, OnStatusUpdateMessage);

            if (!ViewModelBase.IsInDesignModeStatic)
            {
                // Use MEF To load the View Model
                DataContext = App.Container.GetExportedValue<ViewModelBase>(
                    ViewModelTypes.MainPageViewModel);
            }
            // set up the current window
            homeScreen = new Home();
            ContentFrame.Navigate(homeScreen);
        }

        #endregion "Constructor"

        #region "Private Event Handler"

        private void Link0_Click(object sender, RoutedEventArgs e)
        {
            if (homeScreen == null) homeScreen = new Home();
            ContentFrame.Navigate(homeScreen);
        }

        private void InstructorLink_Click(object sender, RoutedEventArgs e)
        {
            if (instructorPage == null) instructorPage = new InstructorPage();
            ContentFrame.Navigate(instructorPage);
        }

        private void StudentLink_Click(object sender, RoutedEventArgs e)
        {
            if (studentPage == null) studentPage = new StudentPage();
            ContentFrame.Navigate(studentPage);
        }

        private void CourseLink_Click(object sender, RoutedEventArgs e)
        {
            if (coursePage == null) coursePage = new CoursePage();
            ContentFrame.Navigate(coursePage);
        }
        
        #endregion "Private Event Handler"

        #region "RaiseErrorMessage"

        private void OnRaiseErrorMessage(Exception ex)
        {
            if (ex != null)
            {
                ErrorWindow win = ErrorWindow.CreateNew(ex);
                LayoutRoot.Children.Add(win);
                win.Show();
            }
        }

        #endregion "RaiseErrorMessage"

        #region "PleaseConfirmMessage"

        private static void OnPleaseConfirmMessage(DialogMessage dialogMessage)
        {
            if (dialogMessage != null)
            {
                MessageBoxResult result = MessageBox.Show(dialogMessage.Content,
                    dialogMessage.Caption, dialogMessage.Button);

                dialogMessage.ProcessCallback(result);
            }
        }

        #endregion "PleaseConfirmMessage"

        #region "StatusUpdateMessage"

        private static void OnStatusUpdateMessage(DialogMessage dialogMessage)
        {
            if (dialogMessage != null)
            {
                MessageBoxResult result = MessageBox.Show(dialogMessage.Content,
                    dialogMessage.Caption, dialogMessage.Button);

                dialogMessage.ProcessCallback(result);
            }
        }

        #endregion "StatusUpdateMessage"
    }
}

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
Software Developer (Senior)
United States United States
Weidong has been an information system professional since 1990. He has a Master's degree in Computer Science, and is currently a MCSD .NET

Comments and Discussions