Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
285
Hover/Unhover Issue
posted

I seem to have a flickering issue with a popup that shows up on hover. When the popup is open and the mouse goes over the popup, the popup flickers because its constantly trying to figure out which element its over and what data to pull. The problem is fixed when I remove the unhover event, but then when the mouse is off the map the popup is still open. Is there anyway to prevent the flickering and keep the unhover? I've been trying to figure out a way to set a variable that has a value when the mouse is over an element but that is null when its just over the background. Any ideas?

Parents
  • 30692
    Suggested Answer
    Offline posted

    This would be one way of approaching it:

     

     public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
                _popup = thePopup;
                _popup.Child.MouseEnter += 
                    new MouseEventHandler(Child_MouseEnter);
                _popup.Child.MouseLeave += 
                    new MouseEventHandler(Child_MouseLeave);
             }
    
            void Child_MouseLeave(object sender, MouseEventArgs e)
            {
                _mouseOverPopup = false;
                PossiblyHidePopup();
            }
    
            void Child_MouseEnter(object sender, MouseEventArgs e)
            {
                _mouseOverPopup = true;
            }
      
            private Popup _popup;
            private bool _mouseOverPopup;
            private MapElement _hoveredElement;
           
            private void XamWebMap_ElementHover(
                object sender, 
                Infragistics.Silverlight.Map.MapElementHoverEventArgs e)
            {
                _hoveredElement = e.Element;
                TransitionPopup();
            }
    
            private void PossiblyHidePopup()
            {
                //add a low priority item to the 
                //queue to check if popup should be closed.
                Dispatcher.BeginInvoke(TransitionPopup);
            }
    
            private void XamWebMap_ElementUnhover(
                object sender, 
                Infragistics.Silverlight.Map.MapElementHoverEventArgs e)
            {
                _hoveredElement = null;
                PossiblyHidePopup();
            }
    
            private void TransitionPopup()
            {
                if (!_mouseOverPopup && _hoveredElement == null)
                {
                    _popup.IsOpen = false;
                    _popup.DataContext = null;
                }
                else if (_hoveredElement != null && 
                    _popup.DataContext != _hoveredElement)
                {
                    Point pos = _hoveredElement.ActualSymbolOrigin;
                    pos = theMap.Viewport.RootCanvas
                        .RenderTransform.Transform(pos);
                    _popup.HorizontalOffset = pos.X;
                    _popup.VerticalOffset = pos.Y;
                    _popup.IsOpen = true;
                    _popup.DataContext = _hoveredElement;
                }
            }
        }
    

    -Graham

Reply Children