如何在自定义控件中启用操作事件? [英] How to enable manipulation events in custom control?

查看:23
本文介绍了如何在自定义控件中启用操作事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆