BindingHelper.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*************************************************************************************
  2. Extended WPF Toolkit
  3. Copyright (C) 2007-2013 Xceed Software Inc.
  4. This program is provided to you under the terms of the Microsoft Public
  5. License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
  6. For more features, controls, and fast professional support,
  7. pick up the Plus Edition at http://xceed.com/wpf_toolkit
  8. Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
  9. ***********************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Windows;
  15. using System.ComponentModel;
  16. using System.Windows.Data;
  17. using System.Windows.Threading;
  18. namespace Xceed.Wpf.AvalonDock.Controls
  19. {
  20. class BindingHelper
  21. {
  22. public static void RebindInactiveBindings(DependencyObject dependencyObject)
  23. {
  24. foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(dependencyObject.GetType()))
  25. {
  26. var dpd = DependencyPropertyDescriptor.FromProperty(property);
  27. if (dpd != null)
  28. {
  29. BindingExpressionBase binding = BindingOperations.GetBindingExpressionBase(dependencyObject, dpd.DependencyProperty);
  30. if (binding != null)
  31. {
  32. //if (property.Name == "DataContext" || binding.HasError || binding.Status != BindingStatus.Active)
  33. {
  34. // Ensure that no pending calls are in the dispatcher queue
  35. Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.SystemIdle, (Action)delegate
  36. {
  37. // Remove and add the binding to re-trigger the binding error
  38. dependencyObject.ClearValue(dpd.DependencyProperty);
  39. BindingOperations.SetBinding(dependencyObject, dpd.DependencyProperty, binding.ParentBindingBase);
  40. });
  41. }
  42. }
  43. }
  44. }
  45. }
  46. }
  47. }