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 InstructorPage.xaml
/// </summary>
public partial class InstructorPage
{
#region "Constructor"
public InstructorPage()
{
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.InstructorPageViewModel);
}
// set up OneWayToSource binding from instructorValidationSummary
// to CurrentInstructorHasErrors
var binding = new Binding
{
Path = new PropertyPath("CurrentInstructorHasErrors"),
Mode = BindingMode.OneWayToSource
};
instructorValidationSummary.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();
hireDateLabel.Refresh();
hireDateDescriptionViewer.Refresh();
statusLabel.Refresh();
statusDescriptionViewer.Refresh();
salaryLabel.Refresh();
salaryDescriptionViewer.Refresh();
}
#endregion "CultureChangeMessage"
#region "BeginEditMessage"
private void OnBeginEditMessage(string screenName)
{
switch (screenName)
{
case "Instructor":
nameLabel.Foreground = new SolidColorBrush(Colors.Black);
nameTextBox.IsEnabled = true;
nameDescriptionViewer.Visibility = Visibility.Visible;
hireDateLabel.Foreground = new SolidColorBrush(Colors.Black);
hireDateDatePicker.IsEnabled = true;
hireDateDescriptionViewer.Visibility = Visibility.Visible;
statusLabel.Foreground = new SolidColorBrush(Colors.Black);
statusComboBox.IsEnabled = true;
statusDescriptionViewer.Visibility = Visibility.Visible;
salaryLabel.Foreground = new SolidColorBrush(Colors.Black);
salaryDoubleUpDown.IsEnabled = true;
salaryDescriptionViewer.Visibility = Visibility.Visible;
var instructorBinding = new Binding
{
Source = (Application.Current.Resources["ApplicationResources"]),
Path = new PropertyPath("Strings.ButtonCommit")
};
editCommitInstructorButton.SetBinding(ContentControl.ContentProperty, instructorBinding);
break;
}
}
#endregion "BeginEditMessage"
#region "EndEditMessage"
private void OnEndEditMessage(string screenName)
{
switch (screenName)
{
case "Instructor":
nameLabel.Foreground = new SolidColorBrush(Colors.Gray);
nameTextBox.IsEnabled = false;
nameDescriptionViewer.Visibility = Visibility.Collapsed;
hireDateLabel.Foreground = new SolidColorBrush(Colors.Gray);
hireDateDatePicker.IsEnabled = false;
hireDateDescriptionViewer.Visibility = Visibility.Collapsed;
statusLabel.Foreground = new SolidColorBrush(Colors.Gray);
statusComboBox.IsEnabled = false;
statusDescriptionViewer.Visibility = Visibility.Collapsed;
salaryLabel.Foreground = new SolidColorBrush(Colors.Gray);
salaryDoubleUpDown.IsEnabled = false;
salaryDescriptionViewer.Visibility = Visibility.Collapsed;
var instructorBinding = new Binding
{
Source = (Application.Current.Resources["ApplicationResources"]),
Path = new PropertyPath("Strings.ButtonEdit")
};
editCommitInstructorButton.SetBinding(ContentControl.ContentProperty, instructorBinding);
break;
}
}
#endregion "EndEditMessage"
#region "CancelEditMessage"
private void OnCancelEditMessage(string screenName)
{
switch (screenName)
{
case "Instructor":
nameLabel.Foreground = new SolidColorBrush(Colors.Gray);
nameTextBox.IsEnabled = false;
nameDescriptionViewer.Visibility = Visibility.Collapsed;
hireDateLabel.Foreground = new SolidColorBrush(Colors.Gray);
hireDateDatePicker.IsEnabled = false;
hireDateDescriptionViewer.Visibility = Visibility.Collapsed;
statusLabel.Foreground = new SolidColorBrush(Colors.Gray);
statusComboBox.IsEnabled = false;
statusDescriptionViewer.Visibility = Visibility.Collapsed;
salaryLabel.Foreground = new SolidColorBrush(Colors.Gray);
salaryDoubleUpDown.IsEnabled = false;
salaryDescriptionViewer.Visibility = Visibility.Collapsed;
var instructorBinding = new Binding
{
Source = (Application.Current.Resources["ApplicationResources"]),
Path = new PropertyPath("Strings.ButtonEdit")
};
editCommitInstructorButton.SetBinding(ContentControl.ContentProperty, instructorBinding);
break;
}
}
#endregion "CancelEditMessage"
}
}