view delete me/SilverlightValidation/Views/UserView.xaml.cs @ 59:3591c26bd63e

MVVMLight added
author Steven Hollidge <stevenhollidge@hotmail.com>
date Sat, 21 Apr 2012 19:20:28 +0100
parents
children
line wrap: on
line source

using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using SilverlightValidation.ViewModels;
using SilverlightValidation.Models;
using SilverlightValidation.Validators;

namespace SilverlightValidation.Views
{
    public partial class UserView
    {
        private UserViewModel vm;
        public UserView()
        {
            InitializeComponent();
            HtmlPage.Document.SetProperty("title", "Silverlight Validation");

            vm = new UserViewModel(UserModel.Create(), new UserModelValidator());
            this.DataContext = vm;
        }

        private static void UpdateTextBoxSource(object sender)
        {
            BindingExpression be = ((TextBox)sender).GetBindingExpression(TextBox.TextProperty);
            be.UpdateSource();
        }

        private void DatePicker_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key != Key.Tab)
                e.Handled = true;
        }

        private void tbUsername_LostFocus(object sender, RoutedEventArgs e)
        {
            UpdateTextBoxSource(sender);
        }

        private void tbPassword_LostFocus(object sender, RoutedEventArgs e)
        {
            BindingExpression be = ((PasswordBox)sender).GetBindingExpression(PasswordBox.PasswordProperty);
            be.UpdateSource();
        }

        private void tbEmail_LostFocus(object sender, RoutedEventArgs e)
        {
            UpdateTextBoxSource(sender);
        }

        private void dpDateOfBirth_LostFocus(object sender, RoutedEventArgs e)
        {
            BindingExpression be = ((DatePicker)sender).GetBindingExpression(DatePicker.SelectedDateProperty);
            be.UpdateSource();
        }
    }
}