我有一个使用WPF,Caliburn和PDF tron的应用程序。它绘制图像页面,并通过它们进行渲染。浏览可以通过多种方式完成,通过特定按钮或按特定的canavas区域。绘制区域的一部分是活动内容的小图标(Web链接,图像等)。当这些图标在它们上面检测到鼠标时,它们会被动画化。当我移动到下一页或上一页时,除了canavas hit area以外的任何东西,我都很好。当我尝试canavas区域时,图标停止工作。一旦我切换到另一个窗口,它就开始工作了(这使得它很难调试,因为visual studio是另一个窗口),或者当我点击应用程序窗口的任何地方时。我一直在调试这个,似乎处理动画的事件永远不会被路由到图标,而图标永远不会意识到鼠标在它上面的事实。只有canavas收到通知。可以somone请告知解决方案或正确的故障排除方法?
(代码如下)
绘图图标功能:
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;
}
}
图标类本身,继承自图像
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;
}
}
}
}