1

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 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

when I do a clean+build the squiggly vanishes but the custom control has an H RESULT e_fail error. So please can you try creating a custom control, maybe just a grid. And adding the behavior to it then applying the control to a page to see if you can reproduce the issue there. Maybe I should update my question wirh that
I did,I created a Templated Control, added a grid in the xaml with EventTrigger inside. And I used it in the main page. but I didn't have the error. Could you please share a basic demo that can reproduce this problem?
Okay, I will update the question when I get home which will be in a couple of hours
I can confirm that after I restarted the project (copied the files from the old project to a new one and deleted the old one), your answer works. So I'm accepting your answer as it solves the issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.