PageRenderTime 25ms CodeModel.GetById 17ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/Visual Studio 2008/CSWPFAnimationWhenDataChanged/MainWindow.xaml.cs

#
C# | 79 lines | 47 code | 6 blank | 26 comment | 0 complexity | 368b4764979539ea6ebebadacc51afb1 MD5 | raw file
 1/************************************* Module Header **************************************\
 2* Module Name:  MainWindow.xaml.cs
 3* Project:      CSWPFAnimationWhenDataChanged
 4* Copyright (c) Microsoft Corporation.
 5* 
 6* This example demonstrates how to trigger animation when the value of the datagrid cell is
 7* changed.
 8* 
 9* 
10* This source is subject to the Microsoft Public License.
11* See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
12* All other rights reserved.
13* 
14* History:
15* * 11/30/2009 3:00 PM Bruce Zhou Created
16 * 
17\******************************************************************************************/
18
19using System;
20using System.Collections.Generic;
21using System.Linq;
22using System.Text;
23using System.Windows;
24using System.Windows.Controls;
25using System.Windows.Data;
26using System.Windows.Documents;
27using System.Windows.Input;
28using System.Windows.Media;
29using System.Windows.Media.Imaging;
30using System.Windows.Navigation;
31using System.Windows.Shapes;
32using System.ComponentModel;
33using System.Collections.ObjectModel;
34using Microsoft.Windows.Controls;
35using System.Windows.Threading;
36namespace CSWPFAnimationWhenDataChanged
37{
38    public partial class MainWindow : Window
39    {
40        NameList list = new NameList();
41        public MainWindow()
42        {
43            InitializeComponent();
44            //hook up AutoGeneratingColumn event
45            this.dataGrid1.AutoGeneratingColumn += 
46                new EventHandler<
47                    Microsoft.Windows.Controls.DataGridAutoGeneratingColumnEventArgs>(
48                    dataGrid1_AutoGeneratingColumn);
49            this.DataContext = list;    
50            
51        }
52        //set NotifyOnTargetUpdated property of each binding to true.
53        void dataGrid1_AutoGeneratingColumn(object sender, 
54            Microsoft.Windows.Controls.DataGridAutoGeneratingColumnEventArgs e)
55        {
56
57            Binding binding = (e.Column as DataGridTextColumn).Binding as Binding;
58            binding.NotifyOnTargetUpdated = true;
59            
60        }
61
62
63        /// <summary>
64        /// Handles the Click event of the btnHookupAnimation control, 
65        /// apply the style for each column here.
66        /// </summary>
67        /// <param name="sender">The source of the event.</param>
68        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> 
69        /// instance containing the event data.</param>
70        private void btnHookupAnimation_Click(object sender, RoutedEventArgs e)
71        {
72            foreach (var col in dataGrid1.Columns)
73            {
74                DataGridTextColumn textCol = col as DataGridTextColumn;
75                textCol.CellStyle = this.FindResource("cellStyle") as Style;
76            }
77        }
78    }
79}