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 CoursePage.xaml
/// </summary>
public partial class CoursePage
{
#region "Constructor"
public CoursePage()
{
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.CoursePageViewModel);
}
// set up OneWayToSource binding from courseValidationSummary
// to CurrentCourseHasErrors
var courseBinding = new Binding
{
Path = new PropertyPath("CurrentCourseHasErrors"),
Mode = BindingMode.OneWayToSource
};
courseValidationSummary.SetBinding(ValidationSummary.HasErrorsProperty, courseBinding);
// set up OneWayToSource binding from enrollmentValidationSummary
// to CurrentEnrollmentHasErrors
var enrollmentBinding = new Binding
{
Path = new PropertyPath("CurrentEnrollmentHasErrors"),
Mode = BindingMode.OneWayToSource
};
enrollmentValidationSummary.SetBinding(ValidationSummary.HasErrorsProperty, enrollmentBinding);
}
#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;
}
titleLabel.Refresh();
titleDescriptionViewer.Refresh();
instructorLabel.Refresh();
instructorDescriptionViewer.Refresh();
studentLabel.Refresh();
studentDescriptionViewer.Refresh();
paidLabel.Refresh();
paidDescriptionViewer.Refresh();
startDateLabel.Refresh();
startDateDescriptionViewer.Refresh();
endDateLabel.Refresh();
endDateDescriptionViewer.Refresh();
classSizeLabel.Refresh();
classSizeDescriptionViewer.Refresh();
}
#endregion "CultureChangeMessage"
#region "BeginEditMessage"
private void OnBeginEditMessage(string screenName)
{
switch (screenName)
{
case "Course":
titleLabel.Foreground = new SolidColorBrush(Colors.Black);
titleTextBox.IsEnabled = true;
titleDescriptionViewer.Visibility = Visibility.Visible;
instructorLabel.Foreground = new SolidColorBrush(Colors.Black);
instructorComboBox.IsHitTestVisible = true;
instructorComboBox.IsTabStop = true;
instructorComboBox.Foreground = new SolidColorBrush(Colors.Black);
instructorDescriptionViewer.Visibility = Visibility.Visible;
startDateLabel.Foreground = new SolidColorBrush(Colors.Black);
startDateDatePicker.IsEnabled = true;
startDateDescriptionViewer.Visibility = Visibility.Visible;
endDateLabel.Foreground = new SolidColorBrush(Colors.Black);
endDateDatePicker.IsEnabled = true;
endDateDescriptionViewer.Visibility = Visibility.Visible;
classSizeLabel.Foreground = new SolidColorBrush(Colors.Black);
classSizeMaskedTextBox.IsEnabled = true;
classSizeDescriptionViewer.Visibility = Visibility.Visible;
var courseBinding = new Binding();
courseBinding.Source = (App.Current.Resources["ApplicationResources"]);
courseBinding.Path = new PropertyPath("Strings.ButtonCommit");
editCommitCourseButton.SetBinding(Button.ContentProperty, courseBinding);
break;
case "Enrollment":
studentLabel.Foreground = new SolidColorBrush(Colors.Black);
studentComboBox.Foreground = new SolidColorBrush(Colors.Black);
studentDescriptionViewer.Visibility = Visibility.Visible;
paidLabel.Foreground = new SolidColorBrush(Colors.Black);
paidCheckBox.IsEnabled = true;
paidDescriptionViewer.Visibility = Visibility.Visible;
var enrollmentBinding = new Binding();
enrollmentBinding.Source = (App.Current.Resources["ApplicationResources"]);
enrollmentBinding.Path = new PropertyPath("Strings.ButtonCommit");
editCommitEnrollmentButton.SetBinding(Button.ContentProperty, enrollmentBinding);
break;
}
}
#endregion "BeginEditMessage"
#region "EndEditMessage"
private void OnEndEditMessage(string screenName)
{
switch (screenName)
{
case "Course":
titleLabel.Foreground = new SolidColorBrush(Colors.Gray);
titleTextBox.IsEnabled = false;
titleDescriptionViewer.Visibility = Visibility.Collapsed;
instructorLabel.Foreground = new SolidColorBrush(Colors.Gray);
instructorComboBox.IsHitTestVisible = false;
instructorComboBox.IsTabStop = false;
instructorComboBox.Foreground = new SolidColorBrush(Colors.Gray);
instructorDescriptionViewer.Visibility = Visibility.Collapsed;
startDateLabel.Foreground = new SolidColorBrush(Colors.Gray);
startDateDatePicker.IsEnabled = false;
startDateDescriptionViewer.Visibility = Visibility.Collapsed;
endDateLabel.Foreground = new SolidColorBrush(Colors.Gray);
endDateDatePicker.IsEnabled = false;
endDateDescriptionViewer.Visibility = Visibility.Collapsed;
classSizeLabel.Foreground = new SolidColorBrush(Colors.Gray);
classSizeMaskedTextBox.IsEnabled = false;
classSizeDescriptionViewer.Visibility = Visibility.Collapsed;
var courseBinding = new Binding();
courseBinding.Source = (App.Current.Resources["ApplicationResources"]);
courseBinding.Path = new PropertyPath("Strings.ButtonEdit");
editCommitCourseButton.SetBinding(Button.ContentProperty, courseBinding);
break;
case "Enrollment":
studentLabel.Foreground = new SolidColorBrush(Colors.Gray);
studentComboBox.Foreground = new SolidColorBrush(Colors.Gray);
studentDescriptionViewer.Visibility = Visibility.Collapsed;
paidLabel.Foreground = new SolidColorBrush(Colors.Gray);
paidCheckBox.IsEnabled = false;
paidDescriptionViewer.Visibility = Visibility.Collapsed;
var enrollmentBinding = new Binding();
enrollmentBinding.Source = (App.Current.Resources["ApplicationResources"]);
enrollmentBinding.Path = new PropertyPath("Strings.ButtonEdit");
editCommitEnrollmentButton.SetBinding(Button.ContentProperty, enrollmentBinding);
break;
}
}
#endregion "EndEditMessage"
#region "CancelEditMessage"
private void OnCancelEditMessage(string screenName)
{
switch (screenName)
{
case "Course":
titleLabel.Foreground = new SolidColorBrush(Colors.Gray);
titleTextBox.IsEnabled = false;
titleDescriptionViewer.Visibility = Visibility.Collapsed;
instructorLabel.Foreground = new SolidColorBrush(Colors.Gray);
instructorComboBox.IsHitTestVisible = false;
instructorComboBox.IsTabStop = false;
instructorComboBox.Foreground = new SolidColorBrush(Colors.Gray);
instructorDescriptionViewer.Visibility = Visibility.Collapsed;
startDateLabel.Foreground = new SolidColorBrush(Colors.Gray);
startDateDatePicker.IsEnabled = false;
startDateDescriptionViewer.Visibility = Visibility.Collapsed;
endDateLabel.Foreground = new SolidColorBrush(Colors.Gray);
endDateDatePicker.IsEnabled = false;
endDateDescriptionViewer.Visibility = Visibility.Collapsed;
classSizeLabel.Foreground = new SolidColorBrush(Colors.Gray);
classSizeMaskedTextBox.IsEnabled = false;
classSizeDescriptionViewer.Visibility = Visibility.Collapsed;
var courseBinding = new Binding();
courseBinding.Source = (App.Current.Resources["ApplicationResources"]);
courseBinding.Path = new PropertyPath("Strings.ButtonEdit");
editCommitCourseButton.SetBinding(Button.ContentProperty, courseBinding);
break;
case "Enrollment":
studentLabel.Foreground = new SolidColorBrush(Colors.Gray);
studentComboBox.Foreground = new SolidColorBrush(Colors.Gray);
studentDescriptionViewer.Visibility = Visibility.Collapsed;
paidLabel.Foreground = new SolidColorBrush(Colors.Gray);
paidCheckBox.IsEnabled = false;
paidDescriptionViewer.Visibility = Visibility.Collapsed;
var enrollmentBinding = new Binding();
enrollmentBinding.Source = (App.Current.Resources["ApplicationResources"]);
enrollmentBinding.Path = new PropertyPath("Strings.ButtonEdit");
editCommitEnrollmentButton.SetBinding(Button.ContentProperty, enrollmentBinding);
break;
}
}
#endregion "CancelEditMessage"
}
}