1
// Copyright © Microsoft Corporation.
2
// This source is subject to the Microsoft Source License for Silverlight Controls (March 2008 Release).
3
// Please see http://go.microsoft.com/fwlink/?LinkID=111693 for details.
4
// All other rights reserved.
6
using System.Collections.Generic;
7
using System.Diagnostics;
9
namespace System.Windows.Controlsb1
11
internal static class Extensions
13
private static Dictionary<DependencyObject, Dictionary<DependencyProperty, bool>> _suspendedHandlers = new Dictionary<DependencyObject, Dictionary<DependencyProperty, bool>>();
15
public static bool IsHandlerSuspended(this DependencyObject obj, DependencyProperty dependencyProperty)
17
if (_suspendedHandlers.ContainsKey(obj))
19
return _suspendedHandlers[obj].ContainsKey(dependencyProperty);
27
public static void SetValueNoCallback(this DependencyObject obj, DependencyProperty property, object value)
29
obj.SuspendHandler(property, true);
32
obj.SetValue(property, value);
36
obj.SuspendHandler(property, false);
41
private static void SuspendHandler(this DependencyObject obj, DependencyProperty dependencyProperty, bool suspend)
43
if (_suspendedHandlers.ContainsKey(obj))
45
Dictionary<DependencyProperty, bool> suspensions = _suspendedHandlers[obj];
49
Debug.Assert(!suspensions.ContainsKey(dependencyProperty));
50
suspensions[dependencyProperty] = true; // true = dummy value
54
Debug.Assert(suspensions.ContainsKey(dependencyProperty));
55
suspensions.Remove(dependencyProperty);
60
Debug.Assert(suspend);
61
_suspendedHandlers[obj] = new Dictionary<DependencyProperty, bool>();
62
_suspendedHandlers[obj][dependencyProperty] = true;