简体   繁体   English

System.Windows.TriggerAction与System.Windows.Interactivity.TriggerAction

[英]System.Windows.TriggerAction vs System.Windows.Interactivity.TriggerAction

I am trying to port a Silverlight project to WPF, where the project relies on Triggers and Actions to make transformations in the visual state. 我正在尝试将Silverlight项目移植到WPF,该项目依赖于Triggers和Actions在可视状态下进行转换。

I know this works, as I've done this before, but for some reason, in my current version, when I try and add a GoToStateAction (Inheriting from System.Windows.Interactivity.TriggerAction) to the EventTrigger actions collection, I get the error "GoToStateAction" cannot be added to a collection or dictionary of type "TriggerActionCollection" (Which is looking for System.Windows.TriggerAction) 我知道这是可行的,就像我之前做过的一样,但是由于某种原因,在当前版本中,当我尝试将GoToStateAction(继承自System.Windows.Interactivity.TriggerAction)添加到EventTrigger操作集合时,我得到了错误“ GoToStateAction”不能添加到“ TriggerActionCollection”类型的集合或词典中(正在寻找System.Windows.TriggerAction)

What do I have to do to get a GoToStateAction in WPF to work? 我要怎么做才能使WPF中的GoToStateAction起作用? My goal is to use something like the following: (Based off the origional silverlight implementation) 我的目标是使用类似以下的内容:(基于原始的Silverlight实现)

<Grid.Triggers>
    <EventTrigger RoutedEvent="MouseLeave" SourceName="PART_DataWaveGrid">
        <ei:GoToStateAction x:Name="MouseLeaveTrigger" StateName="Collapsed"/>
    </EventTrigger>
    <EventTrigger RoutedEvent="MouseEnter" SourceName="PART_DataWaveGrid">
        <ei:GoToStateAction x:Name="MouseEnterTrigger" StateName="Expanded"/>
    </EventTrigger>
    <EventTrigger RoutedEvent="Loaded">
        <ei:GoToStateAction x:Name="LoadTrigger" StateName="Collapsed"/>
    </EventTrigger>
</Grid.Triggers>

Also - a second question, the EventName no longer exists on EventTrigger, so what should I use instead? 另外-第二个问题,EventTrigger上不再存在EventName,那么我应该使用什么呢? The RoutedEvent looks to fill the need, but I'm not sure. RoutedEvent看起来可以满足需要,但我不确定。

This is very late of course, but since I found this during a related search I'll try to answer it. 这当然很晚了,但是由于我是在相关搜索中找到的,因此我将尽力回答。

The trigger-functionality in System.Windows.Interactivity, developed for good integration with Blend, can not be mixed with the trigger-classes in System.Windows. 为了与Blend良好集成而开发的System.Windows.Interactivity中的触发器功能不能与System.Windows中的触发器类混合。 I would opt for the System.Windows.Interactivity triggers, and modify the code to something like this (not actually tested): 我将选择System.Windows.Interactivity触发器,然后将代码修改为如下所示(未经实际测试):

<i:Interaction.Triggers>
    <i:EventTrigger EventName="MouseLeave" SourceName="PART_DataWaveGrid">
        <ei:GoToStateAction x:Name="MouseLeaveTrigger" StateName="Collapsed"/>
    </i:EventTrigger>
    <i:EventTrigger EventName="MouseEnter" SourceName="PART_DataWaveGrid">
        <ei:GoToStateAction x:Name="MouseEnterTrigger" StateName="Expanded"/>
    </i:EventTrigger>
    <i:EventTrigger EventName="Loaded">
        <ei:GoToStateAction x:Name="LoadTrigger" StateName="Collapsed"/>
    </i:EventTrigger>
</i:Interaction.Triggers>

With namespace i: defined as 使用命名空间i:定义为

 xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM