示例#1
0
 public void Dispose()
 {
     if (Pop != null)
     {
         Pop.IsOpen = false;
     }
     Pop = null;
 }
示例#2
0
        /// <summary>
        ///     Handles changes to the Popup property.
        /// </summary>
        /// <param name="d"><see cref="DependencyObject" /> that fired the event</param>
        /// <param name="e">A <see cref="DependencyPropertyChangedEventArgs" /> that contains the event data.</param>
        private static void OnPopChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var control = (UIElement)d;

            control.MouseEnter += (s, e) =>
            {
                var content = d.GetValue(PopupProperty);

                if (content is string)
                {
                    content = BuildDefaultTextBlock(content?.ToString());
                }

                Pop = new Pop
                {
                    BackgroundBrush = control.GetValue(PopBackgroundBrushProperty) as Brush,
                    Content         = content,
                    PopupAnimation  = PopupAnimation.None,
                    PlacementTarget = control
                };

                if (Pop != null)
                {
                    Pop.IsOpen = true;
                }
            };

            control.MouseLeave += (s, e) =>
            {
                if (Pop != null)
                {
                    Pop.IsOpen = false;
                }
                Pop = null;
            };
        }