UWP 中的行为(事件触发命令错误 [英] Behaviors in UWP (Event trigger command error

查看:21
本文介绍了UWP 中的行为(事件触发命令错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:

我有一个自定义控件,其中控件模板有一个网格.我想为网格点击事件添加一个行为.

I have a custom control where the control template has a grid. I want to add a behavior to the grid tapped event.

我做了什么:

我已经安装了用于托管 UWP 行为的 Nuget 包

I have installed the Nuget package for managed UWP behaviors

Install-Package Microsoft.Xaml.Behaviors.Uwp.Managed

在自定义控件的资源字典中,我引用了以下 xml 命名空间以及其他必要的命名空间

In the custom control's resource dictionary, I have the following xml namespaces referenced along with other necessary namespaces

xmlns:i="using:Microsoft.Xaml.Interactivity"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"

然后在自定义控件中,在网格块中,我有以下内容

Then in the custom control, in the grid block, I have the following

<i:Interaction.Behaviors>
   <core:EventTriggerBehavior EventName="Tapped">
       <core:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=CustomCommand}"/>
    </core:EventTriggerBehavior>
 </i:Interaction.Behaviors>

问题:

core:InvokeCommandAction 有蓝色波浪线和这个错误

The core:InvokeCommandAction has the blue squiggly line with this error

EventTriggerBehavior 类型没有支持直接内容

The type EventTriggerBehavior does not support direct content

重现步骤:

创建自定义控件.没什么特别的,也许只是一个网格.将如上所示的 EventTriggerBehavior 添加到网格中.在应用程序的页面上使用创建的控件

Create a custom control. Nothing special,maybe just a grid. Add the EventTriggerBehavior as shown above to the grid. Use the created control on a page in your application

这就是我被困的地方.我已经做了很多谷歌搜索,但找不到摆脱这个错误的方法.任何帮助和代码更正将不胜感激

This right here is where I'm stuck at. I've done a lot of Google searches and just can't find a way out of this error. Any help and code correction will be appreciated

推荐答案

core:InvokeCommandAction 有蓝色波浪线和这个错误

The core:InvokeCommandAction has the blue squiggly line with this error

EventTriggerBehavior 类型不支持直接内容

The type EventTriggerBehavior does not support direct content

我做了一个基本的演示并重现了这个问题.这是一个 XAML 设计器问题.构建项目后,此错误消失了.因此,请确保您的代码正确无误,然后继续构建您的项目.

I made a basic demo and reproduced this problem. It is a XAML Designer issue. After building the project, this error is gone. So please make sure your codes are correct and go ahead build your project.

这篇关于UWP 中的行为(事件触发命令错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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