Behaviors in UWP (Event trigger command error

社会主义新天地 提交于 2019-12-25 09:51:06

问题


SCENERIO:

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

WHAT I HAVE DONE:

I have installed the Nuget package for managed UWP behaviors

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

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>

ISSUES:

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

The type EventTriggerBehavior does not support direct content

STEPS TO REPRODUCE:

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


回答1:


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

The type EventTriggerBehavior does not support direct content

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.



来源:https://stackoverflow.com/questions/40389984/behaviors-in-uwp-event-trigger-command-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!