如何在自定义控件中启用操作事件?

编程入门 行业动态 更新时间:2024-10-28 02:29:21
本文介绍了如何在自定义控件中启用操作事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在创建一个 Windows Phone 7.5 Silverlight 应用程序.我正在创建一个新的自定义控件:

I am creating a Windows Phone 7.5 Silverlight application. I am creating a new custom control:

public class ChartCanvas : Canvas

当我在另一个页面上使用它时,它不会触发任何事件.这是我的 XAML:

When I use it on another page, it doesn't fire any events. Here is my XAML:

<Controls:ChartCanvas x:Name="chartControl" 
                      Margin="8"
                      DoubleTap="chartControl_DoubleTap" 
                      ManipulationStarted="chartControl_ManipulationStarted" />

如何为该控件启用 DoubleTap 事件和操作事件?

How do I enable the DoubleTap event and manipulation events for this control?

推荐答案

您可能希望将事件绑定到 datacontext 的 ViewModel,因为这将有一个通用控件,可以有不同的事件处理实现.

You probably would want to bind your events to your datacontext's ViewModel since this would have a control that is generic that can have different implementation of handling the events.

>

除非您在代码后面的 ChartCanvas 中明确编码 DoubleTap/ManipulationStarted 的逻辑并且不希望它是通用的,例如用于处理数据/东西,那么这应该没问题

Unless you explicitly coded in the ChartCanvas behind the code the logic for DoubleTap/ManipulationStarted and don't want it to be generic e.g. for handling data/stuff then this should be fine

这篇关于如何在自定义控件中启用操作事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 14:37:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117781.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   控件   事件   操作   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!