0

我有一个使用 WPF、Caliburn 和 PDF tron 的应用程序。它绘制图像页面并允许浏览它们。浏览可以通过多种方式完成,通过特定按钮或通过点击特定的画布区域。绘制区域的一部分是活动内容(网络链接、图像等)的小图标。这些图标在检测到鼠标时会显示动画。当我移动到下一页或上一页时,除了画布命中区域之外,一切都很好。当我尝试画布区域时,图标停止工作。一旦我切换到另一个窗口(这使得调试非常困难,因为 Visual Studio 是另一个窗口),或者当我单击应用程序窗口上的任何位置时,它们就会开始工作。我一直在调试这个,似乎处理动画的事件永远不会路由到图标,并且图标永远不会知道鼠标在它上面的事实。只有 canavas 收到通知。有人可以建议解决方案或正确的故障排除方法吗?

(代码如下)

绘图图标功能:

public LinkIcon DrawInteractivityIcon(ICensoredNameLinkIconable link)
    {
        try
        {
            Debug.WriteLine("Drawing Icon on canvas");
            LinkIcon icon = new LinkIcon(link);
            icon.Width = Defaults.CensoredNameIconSize;
            icon.Height = Defaults.CensoredNameIconSize;
            icon.Effect = new DropShadowEffect
            {
                Color = Colors.Gray,
                BlurRadius = Defaults.CensoredNameIconSize / 3 * GetZoom(),
                Opacity = 0.5,
                ShadowDepth = Defaults.CensoredNameIconSize / 7d * GetZoom()
            };

            icon.SetValue(Panel.ZIndexProperty, 210);

            if (link is ICensoredNameLinkTextInfoable)
            {
                ICensoredNameLinkTextInfoable textinfoLink = link as ICensoredNameLinkTextInfoable;
                StringBuilder sb = new StringBuilder();
                sb.Append(textinfoLink.TextInfo);
                if (link is ICensoredNameExpandable)
                {
                    ICensoredNameExpandable expandableLink = link as ICensoredNameLinkExpandable;
                    foreach (ICensoredNameLinkTextInfoable tiLink in expandableLink.AddedLinks.OfType<ICensoredNameLinkTextInfoable>())
                    {
                        sb.AppendLine();
                        sb.Append(tiLink.TextInfo);
                    }
                }
                icon.ToolTip = sb.ToString();
            }

            AddElementToCanvas(icon, 0);

            UpdateCanvasElement(icon, link.IconPosition, link.Page);

            Debug.WriteLine(string.Format("Is icon hitVisible?: {0}", icon.IsHitTestVisible.ToString()));


            return icon;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

从这里调用:(绘制图标,绑定事件委托)

private LinkIcon DrawInteractivityIcon(ICensoredNameLinkIconable link)
    {
        try
        {
            LinkIcon icon = PDFViewer.DrawInteractivityIcon(link);

            icon.MouseEnter += Icon_MouseEnter;
            icon.MouseLeave += Icon_MouseLeave;
            icon.MouseLeftButtonDown += Icon_MouseLeftButtonDown;
            icon.MouseRightButtonDown += Icon_MouseRightButtonDown;
            Debug.WriteLine("Creating icon, binding delegates"); // TODO Clear before going to production

            icon.MouseMove += Icon_MouseMove;
            icon.MouseLeftButtonUp += Icon_MouseLeftButtonUp;

            icon.LongTouch += Icon_LongTouch;

            icon.TouchDown += Icon_TouchDown;
            icon.TouchMove += Icon_TouchMove;
            icon.TouchUp += Icon_TouchUp;
            icon.TouchEnter += Icon_TouchEnter;
            icon.TouchLeave += Icon_TouchLeave;

            return icon;
        }
        catch (Exception ex)
        {
            LogService.LogMessageToXml("Draw icon exception: " + ex.Message, ex);
            return null;
        }
    }

图标类本身,继承自 image

public class LinkIcon : Image
{ <....probably nothing interesting except inheritance... >}

代表控制动画:

    private void Icon_MouseMove(object sender, MouseEventArgs e)
    {
        Debug.WriteLine(string.Format("Calling Mouse Move! Move Mouse move! at {0}", DateTime.Now.ToString()) );  //TODO clear beore going to production
        System.Windows.Point currentPosition = e.GetPosition(this.PDFViewer);          
        if (_movingElement != null)
        {
            if (PDFViewer.ReaderMode == ReaderModes.CustomInteractivity)
            {
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    PDFViewer.MoveElementToPoint(_movingElement, currentPosition);
                    e.Handled = true;
                }
            }
        }
    }
4

0 回答 0