PageRenderTime 75ms CodeModel.GetById 25ms RepoModel.GetById 1ms 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. using System;
  19. using System.Collections.Generic;
  20. using System.Linq;
  21. using System.Text;
  22. using System.Windows;
  23. using System.Windows.Controls;
  24. using System.Windows.Data;
  25. using System.Windows.Documents;
  26. using System.Windows.Input;
  27. using System.Windows.Media;
  28. using System.Windows.Media.Imaging;
  29. using System.Windows.Navigation;
  30. using System.Windows.Shapes;
  31. using System.ComponentModel;
  32. using System.Collections.ObjectModel;
  33. using Microsoft.Windows.Controls;
  34. using System.Windows.Threading;
  35. namespace CSWPFAnimationWhenDataChanged
  36. {
  37. public partial class MainWindow : Window
  38. {
  39. NameList list = new NameList();
  40. public MainWindow()
  41. {
  42. InitializeComponent();
  43. //hook up AutoGeneratingColumn event
  44. this.dataGrid1.AutoGeneratingColumn +=
  45. new EventHandler<
  46. Microsoft.Windows.Controls.DataGridAutoGeneratingColumnEventArgs>(
  47. dataGrid1_AutoGeneratingColumn);
  48. this.DataContext = list;
  49. }
  50. //set NotifyOnTargetUpdated property of each binding to true.
  51. void dataGrid1_AutoGeneratingColumn(object sender,
  52. Microsoft.Windows.Controls.DataGridAutoGeneratingColumnEventArgs e)
  53. {
  54. Binding binding = (e.Column as DataGridTextColumn).Binding as Binding;
  55. binding.NotifyOnTargetUpdated = true;
  56. }
  57. /// <summary>
  58. /// Handles the Click event of the btnHookupAnimation control,
  59. /// apply the style for each column here.
  60. /// </summary>
  61. /// <param name="sender">The source of the event.</param>
  62. /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/>
  63. /// instance containing the event data.</param>
  64. private void btnHookupAnimation_Click(object sender, RoutedEventArgs e)
  65. {
  66. foreach (var col in dataGrid1.Columns)
  67. {
  68. DataGridTextColumn textCol = col as DataGridTextColumn;
  69. textCol.CellStyle = this.FindResource("cellStyle") as Style;
  70. }
  71. }
  72. }
  73. }