【问题标题】:MVVM EventToCommand not found未找到 MVVM EventToCommand
【发布时间】:2014-10-06 10:50:48
【问题描述】:

大家好,我正在尝试在列表框的项目中实现点击效果,但我不断收到此错误:

找不到类型“cmd:EventToCommand”。确认您没有丢失程序集引用,并且所有引用的程序集都已构建。

<catel:UserControl
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:catel="http://catel.codeplex.com"
         xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
         xmlns:cmd="http://www.galasoft.ch/mvvmlight"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">

以及我尝试实现 on click 方法的代码:

<Grid>
    <ItemsControl ItemsSource="{Binding Source={StaticResource cvsRoutes}}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Expander Header="{Binding Name}" MinHeight="50">
                    <ListBox>
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="PreviewMouseLeftButtonDown">
                                <cmd:EventToCommand Command="{Binding PreviewMouseLeftButtonDownCommand}" PassEventArgsToCommand="True"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                        <TextBlock Text="Something" >
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="KeyUp">
                                <cmd:EventToCommand Command="{Binding KeyUpCommand}" PassEventArgsToCommand="True"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                        </TextBlock>
                        <TextBlock Text="Something" />
                        <TextBlock Text="Something" />
                        <TextBlock Text="Something" />
                        <TextBlock Text="Something" />
                    </ListBox>
                </Expander>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</Grid>

你能告诉我是什么问题吗?我该如何解决?

【问题讨论】:

  • 是 Catel 的 EventToCommand 部分吗?我认为这是棱镜的一部分。毫无疑问,它不是 .NET Framework 的一部分
  • soo ...解决方案是什么?
  • 自己实现类或使用像 PRISM 这样的框架。如果您使用 Google,您将找到该课程的来源。
  • 没有找到你错的问题 EventToCommand 是 Catel 的一部分,我只是声明它错了"catel.codeplex.com"
  • 啊好吧 :) 一切都还好。 @斯蒂安。我不知道这个类存在于哪个框架中:P

标签: c# wpf mvvm


【解决方案1】:

有一份很好的列表,列出了 Catel 中可用的所有行为和触发器以及如何使用它们:

https://catelproject.atlassian.net/wiki/pages/viewpage.action?pageId=1409064

它还包括EventToCommand:

https://catelproject.atlassian.net/wiki/display/CTL/EventToCommand

【讨论】:

    【解决方案2】:

    GalaSoft.MvvmLight 库添加到引用中。那么

    使用这个xmlns:cmd="clr-namespace:GalaSoft.MvvmLight;assembly=GalaSoft.MvvmLight" 而不是xmlns:cmd="http://www.galasoft.ch/mvvmlight"

    【讨论】:

      【解决方案3】:

      EventToCommand 是 MVVM-Light 的一部分...这是 MVVM light (Laurent Bugnion) 的作者写的 article on MSDN,他在其中谈到了如何使用它。

      您也可以查看类似的answer here,但我想您的选择是使用 MVVM-Light 如果您想使用它,或者整理他的代码并自己实现类似的东西......

      【讨论】:

      • nahh 找到了问题,感谢您的帮助,尽管我声明 cmd 错误,它应该是 xmlns:cmd="catel.codeplex.com"
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-17
      • 2018-09-04
      • 1970-01-01
      • 1970-01-01
      • 2011-12-23
      • 2015-09-26
      • 2013-02-25
      相关资源
      最近更新 更多