DataGridItemAttachedStorage.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / Controls / DataGridItemAttachedStorage.cs / 1305600 / DataGridItemAttachedStorage.cs

                            //---------------------------------------------------------------------------- 
//
// Copyright (C) Microsoft Corporation.  All rights reserved.
//
//--------------------------------------------------------------------------- 

using System; 
using System.Collections.Generic; 
using System.Windows;
 
namespace System.Windows.Controls
{
    /// 
    ///     Holds all of the information that we need to attach to row items so that we can restore rows when they're devirtualized. 
    /// 
    internal class DataGridItemAttachedStorage 
    { 
        public void SetValue(object item, DependencyProperty property, object value)
        { 
            var map = EnsureItem(item);
            map[property] = value;
        }
 
        public bool TryGetValue(object item, DependencyProperty property, out object value)
        { 
            value = null; 
            Dictionary map;
 
            EnsureItemStorageMap();
            if (_itemStorageMap.TryGetValue(item, out map))
            {
                return map.TryGetValue(property, out value); 
            }
 
            return false; 
        }
 
        public void ClearValue(object item, DependencyProperty property)
        {
            Dictionary map;
 
            EnsureItemStorageMap();
            if (_itemStorageMap.TryGetValue(item, out map)) 
            { 
                map.Remove(property);
            } 
        }

        public void ClearItem(object item)
        { 
            EnsureItemStorageMap();
            _itemStorageMap.Remove(item); 
        } 

        public void Clear() 
        {
            _itemStorageMap = null;
        }
 
        private void EnsureItemStorageMap()
        { 
            if (_itemStorageMap == null) 
            {
                _itemStorageMap = new Dictionary>(); 
            }
        }

        private Dictionary EnsureItem(object item) 
        {
            Dictionary map; 
 
            EnsureItemStorageMap();
            if (!_itemStorageMap.TryGetValue(item, out map)) 
            {
                map = new Dictionary();
                _itemStorageMap[item] = map;
            } 

            return map; 
        } 

        ///  
        ///     A map between row items and the associated data.
        /// 
        private Dictionary> _itemStorageMap;
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK