~ubuntu-branches/ubuntu/karmic/moon/karmic

« back to all changes in this revision

Viewing changes to class/Microsoft.SilverlightControls/Controls/Data/src/Extensions.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-14 12:01:08 UTC
  • Revision ID: james.westby@ubuntu.com-20090214120108-06539vb25vhbd8bn
Tags: upstream-1.0
Import upstream version 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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. 
 
5
 
 
6
using System.Collections.Generic;
 
7
using System.Diagnostics; 
 
8
 
 
9
namespace System.Windows.Controlsb1
 
10
 
11
    internal static class Extensions
 
12
    {
 
13
        private static Dictionary<DependencyObject, Dictionary<DependencyProperty, bool>> _suspendedHandlers = new Dictionary<DependencyObject, Dictionary<DependencyProperty, bool>>(); 
 
14
 
 
15
        public static bool IsHandlerSuspended(this DependencyObject obj, DependencyProperty dependencyProperty)
 
16
        { 
 
17
            if (_suspendedHandlers.ContainsKey(obj)) 
 
18
            {
 
19
                return _suspendedHandlers[obj].ContainsKey(dependencyProperty); 
 
20
            }
 
21
            else
 
22
            { 
 
23
                return false;
 
24
            }
 
25
        } 
 
26
 
 
27
        public static void SetValueNoCallback(this DependencyObject obj, DependencyProperty property, object value)
 
28
        { 
 
29
            obj.SuspendHandler(property, true);
 
30
            try
 
31
            { 
 
32
                obj.SetValue(property, value);
 
33
            }
 
34
            finally 
 
35
            { 
 
36
                obj.SuspendHandler(property, false);
 
37
            } 
 
38
 
 
39
        }
 
40
 
 
41
        private static void SuspendHandler(this DependencyObject obj, DependencyProperty dependencyProperty, bool suspend)
 
42
        {
 
43
            if (_suspendedHandlers.ContainsKey(obj)) 
 
44
            { 
 
45
                Dictionary<DependencyProperty, bool> suspensions = _suspendedHandlers[obj];
 
46
 
 
47
                if (suspend)
 
48
                {
 
49
                    Debug.Assert(!suspensions.ContainsKey(dependencyProperty)); 
 
50
                    suspensions[dependencyProperty] = true; // true = dummy value
 
51
                }
 
52
                else 
 
53
                { 
 
54
                    Debug.Assert(suspensions.ContainsKey(dependencyProperty));
 
55
                    suspensions.Remove(dependencyProperty); 
 
56
                }
 
57
            }
 
58
            else 
 
59
            {
 
60
                Debug.Assert(suspend);
 
61
                _suspendedHandlers[obj] = new Dictionary<DependencyProperty, bool>(); 
 
62
                _suspendedHandlers[obj][dependencyProperty] = true; 
 
63
            }
 
64
        } 
 
65
    }
 
66
}