aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionListBoxItem.cs
blob: 55d752bfdca4bfa2b65245fe61b16de9905505e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace Tango.Scripting.Editors.CodeCompletion
{
    public class CompletionListBoxItem : ListBoxItem
    {
        public ToolTip toolTip;

        public DataTemplate ToolTipContentTemplate
        {
            get { return (DataTemplate)GetValue(ToolTipContentTemplateProperty); }
            set { SetValue(ToolTipContentTemplateProperty, value); }
        }
        public static readonly DependencyProperty ToolTipContentTemplateProperty =
            DependencyProperty.Register("ToolTipContentTemplate", typeof(DataTemplate), typeof(CompletionListBoxItem), new PropertyMetadata(null));

        public CompletionListBoxItem()
        {
            toolTip = new ToolTip();
            toolTip.PlacementTarget = this;
            toolTip.HorizontalOffset = 15;
            toolTip.Background = Brushes.Transparent;
            toolTip.BorderThickness = new Thickness(0);
            toolTip.Opacity = 1;
            toolTip.HasDropShadow = true;
            toolTip.Placement = System.Windows.Controls.Primitives.PlacementMode.Right;
            this.Unloaded += CompletionListBoxItem_Unloaded;
        }

        private void CompletionListBoxItem_Unloaded(object sender, RoutedEventArgs e)
        {
            toolTip.StaysOpen = false;
            toolTip.IsOpen = false;
        }

        protected override void OnSelected(RoutedEventArgs e)
        {
            try
            {
                base.OnSelected(e);
                toolTip.Content = DataContext;
                toolTip.ContentTemplate = ToolTipContentTemplate;
                toolTip.StaysOpen = true;
                toolTip.IsOpen = true;
            }
            catch { }
        }

        protected override void OnUnselected(RoutedEventArgs e)
        {
            base.OnUnselected(e);
            toolTip.StaysOpen = false;
            toolTip.IsOpen = false;
        }
    }
}