c# - 未在自定义控件中的 UI 元素上触发指针事件
问题描述
我正在创建一个UserControl
包含多个UI Elements
. 由于要渲染的数量取决于用户的输入,因此将其UserControl
渲染为StackPanel
using 。ItemsControl
UserControls
中的基本 XAMLUserControl
如下所示。
<Grid x:Name="Viewport" VerticalAlignment="Top" HorizontalAlignment="Center">
<Border x:Name="ViewportBorder" Background="White" BorderThickness="2, 2, 2, 2" BorderBrush="#FF353334" />
<Image x:Name="Image" Margin="0" UseLayoutRounding="True" ManipulationMode="Scale"/>
<InkCanvas x:Name="InkCanvas" />
<Canvas x:Name="SelectionCanvas" CompositeMode="SourceOver" />
</Grid>
当用户将鼠标悬停在 上时,我想更改光标图标SelectionCanvas
(基于我在源代码中看到的条件检查)。这看起来很简单,所以我尝试使用PointerEntered
&PointerExited
事件从SelectionCanvas
. 并PointerMoved
更改光标图标。但似乎没有任何事件被触发。
我也尝试绑定到Viewport
网格元素,但也没有运气。
我不确定我在这里错过了什么。有人可以帮我吗?任何帮助深表感谢。请在此处找到完整的源代码。
- 请注意,启动项目中包含一个示例 PDF
/Resources
,您必须从应用程序中打开它。
解决方案
PointerEntered
和事件被引发,PointerExited
前提是应该引发它们的区域被绘制,因此尝试将 的Background
属性设置Canvas
为一些画笔,例如Transparent
:
<Canvas x:Name="SelectionCanvas" CompositeMode="SourceOver"
Background="Transparent"
PointerEntered="SelectionCanvas_PointerEntered"
...
推荐阅读
- r - 在这种情况下,我可以使用“连续”随机效果(使用 lmer)吗?
- html - 为什么引导 col 内容不会增加宽度?
- laravel - Laravel 中的访问布局
- c# - 远程验证命中功能两次
- cloudflare - Cloudflare Logpush 中的文件名
- sql - 如何使用 Sequel Pro 解析可变字符串文本大小的数据
- mysql - 二进制数据不能用Embulk复制
- mysql - 为什么block_ops_in block_ops_out 在mysql 中总是为零?
- node.js - 使用存档数据库模式管理旧数据的最佳实践是什么?
- typescript - 为什么 TypeScript 在推断函数的返回类型时不会自动使用文字类型?