gpt4 book ai didi

c# - WPF&MVVM : Library System. Windows.Interactivity 不再可用?

转载 作者:行者123 更新时间:2023-11-30 20:29:07 25 4
gpt4 key购买 nike

我需要通过 Reference Manager 添加 System.Windows.Interactivity.dll 库。在Visual Studio 2017中,我没有找到。从 System.Windows 开始的所有搜索结果显示在下面的屏幕截图中:

enter image description here

我以为这个库会内置在当前 Visual Studio 版本的 WPF 项目中,所以当我添加下面的 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 标记时,它表示 InteractionEventTriggerInvokeCommandAction 具有未在 clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity 命名空间中找到:

<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 库有关系还是没有,我该怎么做才能解决这个问题?

最佳答案

目前,需要通过 NuGet 包管理器添加 System.Windows.Interactivity.WPF

enter image description here

关于c# - WPF&MVVM : Library System. Windows.Interactivity 不再可用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46556240/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com