Click here to Skip to main content
15,881,867 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.2K   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.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using GalaSoft.MvvmLight;
using SchoolSample.Common;

namespace SchoolSample
{
    /// <summary>
    /// Interaction logic for StudentPage.xaml
    /// </summary>
    public partial class StudentPage : Page
    {
        #region "Constructor"

        public StudentPage()
        {
            InitializeComponent();

            // register for BeginEditMessage
            AppMessages.BeginEditMessage.Register(this, OnBeginEditMessage);
            // register for EndEditMessage
            AppMessages.EndEditMessage.Register(this, OnEndEditMessage);
            // register for CancelEditMessage
            AppMessages.CancelEditMessage.Register(this, OnCancelEditMessage);

            if (!ViewModelBase.IsInDesignModeStatic)
            {
                // Use MEF To load the View Model
                DataContext = App.Container.GetExportedValue<ViewModelBase>(
                    ViewModelTypes.StudentPageViewModel);
            }

            // set up OneWayToSource binding from studentValidationSummary
            // to CurrentStudentHasErrors
            var binding = new Binding
                              {
                                  Path = new PropertyPath("CurrentStudentHasErrors"),
                                  Mode = BindingMode.OneWayToSource
                              };
            studentValidationSummary.SetBinding(ValidationSummary.HasErrorsProperty, binding);
        }

        #endregion "Constructor"

        #region "BeginEditMessage"

        private void OnBeginEditMessage(string screenName)
        {
            switch (screenName)
            {
                case "Student":
                    nameLabel.Foreground = new SolidColorBrush(Colors.Black);
                    nameTextBox.IsEnabled = true;
                    nameDescriptionViewer.Visibility = Visibility.Visible;
                    enrollmentDateLabel.Foreground = new SolidColorBrush(Colors.Black);
                    enrollmentDateDatePicker.IsEnabled = true;
                    enrollmentDateDescriptionViewer.Visibility = Visibility.Visible;
                    editCommitStudentButton.Content = "Commit";
                    break;
            }
        }

        #endregion "BeginEditMessage"

        #region "EndEditMessage"

        private void OnEndEditMessage(string screenName)
        {
            switch (screenName)
            {
                case "Student":
                    nameLabel.Foreground = new SolidColorBrush(Colors.Gray);
                    nameTextBox.IsEnabled = false;
                    nameDescriptionViewer.Visibility = Visibility.Collapsed;
                    enrollmentDateLabel.Foreground = new SolidColorBrush(Colors.Gray);
                    enrollmentDateDatePicker.IsEnabled = false;
                    enrollmentDateDescriptionViewer.Visibility = Visibility.Collapsed;
                    editCommitStudentButton.Content = "Edit";
                    break;
            }
        }

        #endregion "EndEditMessage"

        #region "CancelEditMessage"

        private void OnCancelEditMessage(string screenName)
        {
            switch (screenName)
            {
                case "Student":
                    nameLabel.Foreground = new SolidColorBrush(Colors.Gray);
                    nameTextBox.IsEnabled = false;
                    nameDescriptionViewer.Visibility = Visibility.Collapsed;
                    enrollmentDateLabel.Foreground = new SolidColorBrush(Colors.Gray);
                    enrollmentDateDatePicker.IsEnabled = false;
                    enrollmentDateDescriptionViewer.Visibility = Visibility.Collapsed;
                    editCommitStudentButton.Content = "Edit";
                    break;
            }
        }

        #endregion "CancelEditMessage"
    }
}

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