|
using System.Threading;
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
{
#region "Constructor"
public StudentPage()
{
InitializeComponent();
// register for CultureChangeMessage
AppMessages.CultureChangeMessage.Register(this, OnCultureChangeMessage);
// 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 "CultureChangeMessage"
private void OnCultureChangeMessage(string culture)
{
switch (culture)
{
case "en":
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");
break;
case "zh-Hans":
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("zh-Hans");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-Hans");
break;
case "zh-Hant":
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("zh-Hant");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-Hant");
break;
}
nameLabel.Refresh();
nameDescriptionViewer.Refresh();
enrollmentDateLabel.Refresh();
enrollmentDateDescriptionViewer.Refresh();
statusLabel.Refresh();
statusDescriptionViewer.Refresh();
}
#endregion "CultureChangeMessage"
#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;
statusLabel.Foreground = new SolidColorBrush(Colors.Black);
statusComboBox.IsEnabled = true;
statusDescriptionViewer.Visibility = Visibility.Visible;
var studentBinding = new Binding();
studentBinding.Source = (App.Current.Resources["ApplicationResources"]);
studentBinding.Path = new PropertyPath("Strings.ButtonCommit");
editCommitStudentButton.SetBinding(Button.ContentProperty, studentBinding);
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;
statusLabel.Foreground = new SolidColorBrush(Colors.Gray);
statusComboBox.IsEnabled = false;
statusDescriptionViewer.Visibility = Visibility.Collapsed;
var studentBinding = new Binding();
studentBinding.Source = (App.Current.Resources["ApplicationResources"]);
studentBinding.Path = new PropertyPath("Strings.ButtonEdit");
editCommitStudentButton.SetBinding(Button.ContentProperty, studentBinding);
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;
statusLabel.Foreground = new SolidColorBrush(Colors.Gray);
statusComboBox.IsEnabled = false;
statusDescriptionViewer.Visibility = Visibility.Collapsed;
var studentBinding = new Binding();
studentBinding.Source = (App.Current.Resources["ApplicationResources"]);
studentBinding.Path = new PropertyPath("Strings.ButtonEdit");
editCommitStudentButton.SetBinding(Button.ContentProperty, studentBinding);
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.
Weidong has been an information system professional since 1990. He has a Master's degree in Computer Science, and is currently a MCSD .NET