Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/SharpVectorRuntime/SvgImage.cs @ 13354

Last change on this file since 13354 was 12762, checked in by aballeit, 9 years ago

#2283 GUI updates, Tree-chart, MCTS Version 2 (prune leaves)

File size: 2.0 KB
Line 
1using System;
2using System.Windows;
3using System.Windows.Media;
4using System.Windows.Markup;
5using System.Windows.Controls;
6using System.Collections.Generic;
7
8namespace SharpVectors.Runtime
9{
10    //This class, if placed at the root of a XAML file which is loaded by XamlReader.Load()
11    //will end up having all named elements contained in its nameTable automatically...
12    //
13    /// <summary>
14    /// This class, if placed at the root of a XAML file which is loaded by XamlReader.Load()
15    /// will end up having all named elements contained in its nameTable automatically.
16    /// If you want to get that list, it is now in your power.
17    /// </summary>
18    /// <remarks>
19    /// This class is based on the discussion, which can be found here
20    /// <see href="http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/5c226430-c54d-45b8-a8a2-7e4a79e3692a"/>
21    /// </remarks>
22    public sealed class SvgImage : Image, INameScope
23    {
24        #region Private Fields
25
26        private Dictionary<string, object> _nameTable;
27
28        #endregion
29
30        #region Constructors and Destructor
31
32        public SvgImage()
33        {
34            _nameTable = new Dictionary<string, object>();
35        }
36
37        #endregion
38
39        #region INameScope Members
40
41        object INameScope.FindName(string name)
42        {
43            object element = null;
44            _nameTable.TryGetValue(name, out element);
45
46            return element;
47        }
48
49        void INameScope.RegisterName(string name, object scopedElement)
50        {
51            _nameTable[name] = scopedElement;
52
53            DependencyObject namedObject = scopedElement as DependencyObject;
54
55            if (namedObject != null)
56            {   
57                namedObject.SetValue(FrameworkElement.NameProperty, name);
58            }
59        }
60
61        void INameScope.UnregisterName(string name)
62        {
63            _nameTable[name] = null;
64        }
65
66        #endregion
67    }
68}
Note: See TracBrowser for help on using the repository browser.