我需要通过引用管理器
添加System.Windows.Interactivity.dll
库。在Visual Studio 2017
中,我没有找到它。以下是从System.Windows
开始的所有搜索结果,如下图所示:
C#
代码时,没有显示任何来自 IDE 的警告:private RelayCommand doubleCommand;
public RelayCommand DoubleCommand {
get {
return doubleCommand ??
(doubleCommand = new RelayCommand(obj => {
Phone phone = obj as Phone;
if (phone != null) {
Phone phoneCopy = new Phone {
Company = phone.Company,
Price = phone.Price,
Title = phone.Title
};
Phones.Insert(0, phoneCopy);
}
}));
}
}
然而,当我添加以下的
XAML
标记时,它会提示在 clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity
命名空间中找不到 Interaction
、EventTrigger
和 InvokeCommandAction
。<Window x:Class="MVVM_Tutorial.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MVVM_Tutorial"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<!-- ... -->
<Button Content="2x">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<i:InvokeCommandAction
Command="{Binding DoubleCommand}"
CommandParameter="{Binding SelectedPhone}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<!-- ... -->
</Window>
这是否与 System.Windows.Interactivity
库有关,我该怎么解决这个问题?