【发布时间】:2020-07-28 20:18:03
【问题描述】:
我要疯了: 我有一个同时使用 Mahapps.Metro 和 MVVMLight 的应用程序。 基本上大多数事情都可以,直到您尝试使用 Interaction.Triggers。
我通常会遇到类似的错误
Cannot add instance of type 'EventToCommand' to a collection of type 'TriggerActionCollection'. Only items of type 'T' are allowed.
通过我在网上找到的 repo 可以重现此问题: https://github.com/mike-schulze/mahapps-mvvmlight-setup (抱歉,mike 劫持了)并向视图模型添加 Metro SplitButton:
<Controls:SplitButton ItemsSource="{Binding MyList}" Grid.Column="1" Grid.Row="1">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<cmd:EventToCommand
Command="{Binding Mode=TwoWay, Path=SelectionChangedCommand}"
PassEventArgsToCommand="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Controls:SplitButton>
MyList 是
public List<string> MyList
{
get
{
List<string> theList = new List<string>();
theList.Add("Hello");
theList.Add("World");
return theList;
}
}
我不确定 App.config 中有多少不同的命名空间、硬编码的交互性版本,或者我曾经尝试过什么。
有没有人使用 Mahapps Metro(版本不太旧)和 MVVM Light 以及 EventToCommand 的东西的工作示例?
我认为我的问题与 Metro 的更新有关 - 他们现在使用的是行为而不是交互性。我正在使用 Interactivity dll 版本 4.5.0.0。 但即使是我上面提到的旧 git 也显示了问题......而且我找不到有效的解决方案。
非常感谢任何帮助。 谢谢
【问题讨论】:
标签: wpf mvvm-light mahapps.metro eventtocommand