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; } } }