UWP 中的行为(事件触发命令错误
Behaviors in UWP (Event trigger command error
场景:
我有一个自定义控件,其中控件模板有一个网格。我想为网格点击事件添加一个行为。
我做了什么:
我已经为托管 UWP 行为安装了 Nuget 包
Install-Package Microsoft.Xaml.Behaviors.Uwp.Managed
在自定义控件的资源字典中,我引用了以下 xml 命名空间以及其他必要的命名空间
xmlns:i="using:Microsoft.Xaml.Interactivity"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
然后在自定义控件中,在网格块中,我有以下内容
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Tapped">
<core:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=CustomCommand}"/>
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
问题:
core:InvokeCommandAction
有蓝色波浪线和这个错误
The type EventTriggerBehavior does not
support direct content
重现步骤:
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
这就是我被困的地方。我已经进行了很多 Google 搜索,但找不到解决此错误的方法。
任何帮助和代码更正将不胜感激
The core:InvokeCommandAction has the blue squiggly line with this error
The type EventTriggerBehavior does not support direct content
我做了一个基本的demo,重现了这个问题。这是一个 XAML 设计师问题。构建项目后,此错误消失了。因此,请确保您的代码正确无误,然后继续构建您的项目。
场景:
我有一个自定义控件,其中控件模板有一个网格。我想为网格点击事件添加一个行为。
我做了什么:
我已经为托管 UWP 行为安装了 Nuget 包
Install-Package Microsoft.Xaml.Behaviors.Uwp.Managed
在自定义控件的资源字典中,我引用了以下 xml 命名空间以及其他必要的命名空间
xmlns:i="using:Microsoft.Xaml.Interactivity"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
然后在自定义控件中,在网格块中,我有以下内容
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Tapped">
<core:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=CustomCommand}"/>
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
问题:
core:InvokeCommandAction
有蓝色波浪线和这个错误
The type EventTriggerBehavior does not support direct content
重现步骤:
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
这就是我被困的地方。我已经进行了很多 Google 搜索,但找不到解决此错误的方法。 任何帮助和代码更正将不胜感激
The core:InvokeCommandAction has the blue squiggly line with this error
The type EventTriggerBehavior does not support direct content
我做了一个基本的demo,重现了这个问题。这是一个 XAML 设计师问题。构建项目后,此错误消失了。因此,请确保您的代码正确无误,然后继续构建您的项目。