~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core.UI/UserControls/ToolBoxExpander.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
#region Usings
 
5
 
 
6
using System.Linq;
 
7
using System.Windows;
 
8
using System.Windows.Controls;
 
9
using ICSharpCode.Data.EDMDesigner.Core.UI.Helpers;
 
10
 
 
11
#endregion
 
12
 
 
13
namespace ICSharpCode.Data.EDMDesigner.Core.UI.UserControls
 
14
{
 
15
    public class ToolBoxExpander : Expander
 
16
    {
 
17
        static ToolBoxExpander()
 
18
        {
 
19
            ResourceDictionaryLoader.LoadResourceDictionary("/UserControls/ToolBoxExpanderResourceDictionary.xaml");
 
20
        }
 
21
        
 
22
        private RowDefinition _rowDefinition;
 
23
        private GridLength? _rowHeight;
 
24
 
 
25
        private RowDefinition RowDefinition
 
26
        {
 
27
            get
 
28
            {
 
29
                if (_rowDefinition == null)
 
30
                {
 
31
                    FrameworkElement parent = this;
 
32
                    while ((parent = parent.Parent as FrameworkElement) != null)
 
33
                    {
 
34
                        var grid = parent as Grid;
 
35
                        if (grid != null && grid.RowDefinitions.Any())
 
36
                        {
 
37
                            _rowDefinition = grid.RowDefinitions[Grid.GetRow(this)];
 
38
                            break;
 
39
                        }
 
40
                    }
 
41
                }
 
42
                return _rowDefinition;
 
43
            }
 
44
        }
 
45
 
 
46
        protected override void OnCollapsed()
 
47
        {
 
48
            _rowHeight = RowDefinition.Height;
 
49
            RowDefinition.Height = GridLength.Auto;
 
50
            base.OnCollapsed();
 
51
        }
 
52
 
 
53
        protected override void OnExpanded()
 
54
        {
 
55
            base.OnExpanded();
 
56
            if (_rowHeight.HasValue)
 
57
                RowDefinition.Height = _rowHeight.Value;
 
58
        }
 
59
    }
 
60
}