changeset 77:86ed4919b126

Working version!
author Steven Hollidge <stevenhollidge@hotmail.com>
date Mon, 23 Apr 2012 22:06:05 +0100
parents 441fdfce70a7
children dd6bcd2535b6
files SilverlightGlimpse/SilverlightGlimpse/Diagnostics/PropertyPathHelper.cs SilverlightGlimpse/SilverlightValidation/Commands/RelayCommand.cs SilverlightGlimpse/SilverlightValidation/Data/Factory.cs SilverlightGlimpse/SilverlightValidation/Views/UserListView.xaml SilverlightGlimpse/SilverlightValidation/Views/UserView.xaml SilverlightGlimpse/SilverlightValidation/Views/UserView.xaml.cs
diffstat 6 files changed, 52 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/SilverlightGlimpse/SilverlightGlimpse/Diagnostics/PropertyPathHelper.cs	Mon Apr 23 22:05:53 2012 +0100
+++ b/SilverlightGlimpse/SilverlightGlimpse/Diagnostics/PropertyPathHelper.cs	Mon Apr 23 22:06:05 2012 +0100
@@ -5,19 +5,26 @@
 {
     public static class PropertyPathHelper
     {
+        private static readonly Dummy _dummy = new Dummy();
+
         public static object GetValue(object source, string propertyPath)
         {
-            Binding binding = new Binding(propertyPath) {Mode = BindingMode.OneTime, Source = source};
+            var binding = new Binding(propertyPath)
+                              {
+                                  Mode = BindingMode.OneTime, 
+                                  Source = source
+                              };
             BindingOperations.SetBinding(_dummy, Dummy.ValueProperty, binding);
             return _dummy.GetValue(Dummy.ValueProperty);
         }
 
-        private static readonly Dummy _dummy = new Dummy();
-
         private class Dummy : DependencyObject
         {
             public static readonly DependencyProperty ValueProperty =
-                DependencyProperty.Register("Value", typeof (object), typeof (Dummy), new PropertyMetadata(null));
+                DependencyProperty.Register("Value", 
+                                            typeof (object), 
+                                            typeof (Dummy), 
+                                            new PropertyMetadata(null));
         }
     }
 }
--- a/SilverlightGlimpse/SilverlightValidation/Commands/RelayCommand.cs	Mon Apr 23 22:05:53 2012 +0100
+++ b/SilverlightGlimpse/SilverlightValidation/Commands/RelayCommand.cs	Mon Apr 23 22:06:05 2012 +0100
@@ -5,10 +5,8 @@
 {
     public class RelayCommand : ICommand
     {
-        public event EventHandler CanExecuteChanged = delegate { };
-
-        readonly Action<object> _execute;
-        readonly Predicate<object> _canExecute;
+        private readonly Predicate<object> _canExecute;
+        private readonly Action<object> _execute;
 
         public RelayCommand(Action<object> execute,
                             Predicate<object> canExecute = null)
@@ -19,11 +17,9 @@
             _canExecute = canExecute;
         }
 
+        #region ICommand Members
 
-        public void UpdateCanExecuteCommand()
-        {
-            CanExecuteChanged(this, new EventArgs());
-        }
+        public event EventHandler CanExecuteChanged = delegate { };
 
 
         public bool CanExecute(object parameter)
@@ -36,5 +32,12 @@
         {
             _execute(parameter);
         }
+
+        #endregion
+
+        public void UpdateCanExecuteCommand()
+        {
+            CanExecuteChanged(this, new EventArgs());
+        }
     }
-}
+}
\ No newline at end of file
--- a/SilverlightGlimpse/SilverlightValidation/Data/Factory.cs	Mon Apr 23 22:05:53 2012 +0100
+++ b/SilverlightGlimpse/SilverlightValidation/Data/Factory.cs	Mon Apr 23 22:06:05 2012 +0100
@@ -10,11 +10,11 @@
         {
             return new List<UserModel>(5)
             {
-                new UserModel() { Username = "StevenH", Password = "Password1", Email = "steven@hotmail.com", DateOfBirth = new DateTime(1977, 09, 01), Description = ""},
+                new UserModel() { Username = "StevenH", Password = "Password1", Email = "steven@hotmail.com", DateOfBirth = new DateTime(1977, 09, 01), Description = "Great binding works"},
                 new UserModel() { Username = "RichardJ", Password = "12N456a", Email = "dicky@gmail.com", DateOfBirth = new DateTime(1983, 03, 13), Description = "Loves .Net!"},
-                new UserModel() { Username = "BobbyP", Password = "pa33Word", Email = "bob@yahoo.co.uk", DateOfBirth = new DateTime(1992, 08, 30), Description = ""},
+                new UserModel() { Username = "BobbyP", Password = "pa33Word", Email = "bob@yahoo.co.uk", DateOfBirth = new DateTime(1992, 08, 30), Description = "Adores fruit"},
                 new UserModel() { Username = "DavidM", Password = "poIu789", Email = "daveyboy@marsh.com", DateOfBirth = new DateTime(1965, 06, 21), Description = "Java fan boy"},
-                new UserModel() { Username = "JessieJ", Password = "jlkJh567", Email = "jj@apple.co.uk", DateOfBirth = new DateTime(1990, 10, 15), Description = ""}
+                new UserModel() { Username = "JessieJ", Password = "jlkJh567", Email = "jj@apple.co.uk", DateOfBirth = new DateTime(1990, 10, 15), Description = "StackOverflow deity"}
             };
         }
     }
--- a/SilverlightGlimpse/SilverlightValidation/Views/UserListView.xaml	Mon Apr 23 22:05:53 2012 +0100
+++ b/SilverlightGlimpse/SilverlightValidation/Views/UserListView.xaml	Mon Apr 23 22:06:05 2012 +0100
@@ -23,10 +23,21 @@
             <ColumnDefinition Width="*" />
         </Grid.ColumnDefinitions>
 
+        <Button x:Name="btnThrowException"
+                Grid.Row="1"
+                Grid.Column="1"
+                Width="120"
+                HorizontalAlignment="Left"
+                Click="btnThrowException_Click"
+                Content="Throw Exception"
+                Style="{StaticResource ButtonStyle}" />
+
         <StackPanel Grid.Row="1"
                     Grid.Column="1"
                     HorizontalAlignment="Right"
                     Orientation="Horizontal">
+
+
             <Button x:Name="btnAdd"
                     Width="60"
                     Command="{Binding AddCommand}"
@@ -93,14 +104,5 @@
                                              Header="Description" />
             </controls:DataGrid.Columns>
         </controls:DataGrid>
-
-        <Button x:Name="btnThrowException"
-                Grid.Row="4"
-                Grid.Column="1"
-                Width="150"
-                Height="50"
-                HorizontalAlignment="Center"
-                Content="Throw Exception"
-                Click="btnThrowException_Click"/>
     </Grid>
 </UserControl>
--- a/SilverlightGlimpse/SilverlightValidation/Views/UserView.xaml	Mon Apr 23 22:05:53 2012 +0100
+++ b/SilverlightGlimpse/SilverlightValidation/Views/UserView.xaml	Mon Apr 23 22:06:05 2012 +0100
@@ -2,10 +2,6 @@
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:c="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
-               xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
-               xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
-               xmlns:p="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls"
-               xmlns:s="clr-namespace:System;assembly=mscorlib"
                xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
                Title="Add User"
                Width="500"
@@ -120,11 +116,17 @@
         <TextBox Grid.Row="5"
                  Grid.Column="2"
                  Style="{StaticResource TextBoxStyle}"
-                 Text="{Binding Description}" />
+                 Text="{Binding DONEITGAIN}" />
         <StackPanel Grid.Row="6"
                     Grid.Column="2"
                     HorizontalAlignment="Right"
                     Orientation="Horizontal">
+            <Button x:Name="btnThrowException"
+                    Width="120"
+                    Margin="0,0,50,0"
+                    Click="btnThrowException_OnClick"
+                    Content="Throw Exception"
+                    Style="{StaticResource ButtonStyle}" />
             <Button Command="{Binding OkCommand}"
                     Content="OK"
                     Style="{StaticResource ButtonStyle}" />
--- a/SilverlightGlimpse/SilverlightValidation/Views/UserView.xaml.cs	Mon Apr 23 22:05:53 2012 +0100
+++ b/SilverlightGlimpse/SilverlightValidation/Views/UserView.xaml.cs	Mon Apr 23 22:06:05 2012 +0100
@@ -1,4 +1,6 @@
-using System.Windows.Browser;
+using System;
+using System.Windows;
+using System.Windows.Browser;
 using System.Windows.Input;
 using SilverlightValidation.Models;
 using SilverlightValidation.Validators;
@@ -24,5 +26,10 @@
             if (e.Key != Key.Tab)
                 e.Handled = true;
         }
+
+        private void btnThrowException_OnClick(object sender, RoutedEventArgs e)
+        {
+            throw new Exception("Exception from Child Window");
+        }
     }
 }
\ No newline at end of file