comparison 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
comparison
equal deleted inserted replaced
58:241e2f22ed3c 59:3591c26bd63e
1 using System.Windows;
2 using System.Windows.Browser;
3 using System.Windows.Controls;
4 using System.Windows.Data;
5 using System.Windows.Input;
6 using SilverlightValidation.ViewModels;
7 using SilverlightValidation.Models;
8 using SilverlightValidation.Validators;
9
10 namespace SilverlightValidation.Views
11 {
12 public partial class UserView
13 {
14 private UserViewModel vm;
15 public UserView()
16 {
17 InitializeComponent();
18 HtmlPage.Document.SetProperty("title", "Silverlight Validation");
19
20 vm = new UserViewModel(UserModel.Create(), new UserModelValidator());
21 this.DataContext = vm;
22 }
23
24 private static void UpdateTextBoxSource(object sender)
25 {
26 BindingExpression be = ((TextBox)sender).GetBindingExpression(TextBox.TextProperty);
27 be.UpdateSource();
28 }
29
30 private void DatePicker_KeyDown(object sender, KeyEventArgs e)
31 {
32 if (e.Key != Key.Tab)
33 e.Handled = true;
34 }
35
36 private void tbUsername_LostFocus(object sender, RoutedEventArgs e)
37 {
38 UpdateTextBoxSource(sender);
39 }
40
41 private void tbPassword_LostFocus(object sender, RoutedEventArgs e)
42 {
43 BindingExpression be = ((PasswordBox)sender).GetBindingExpression(PasswordBox.PasswordProperty);
44 be.UpdateSource();
45 }
46
47 private void tbEmail_LostFocus(object sender, RoutedEventArgs e)
48 {
49 UpdateTextBoxSource(sender);
50 }
51
52 private void dpDateOfBirth_LostFocus(object sender, RoutedEventArgs e)
53 {
54 BindingExpression be = ((DatePicker)sender).GetBindingExpression(DatePicker.SelectedDateProperty);
55 be.UpdateSource();
56 }
57 }
58 }