首页 > 解决方案 > 如何将命令绑定到表单的加载事件

问题描述

我正在尝试在加载主表单时运行一些代码。我在这里使用了代码。我使用 MVVM 模式将 wpf 与 .NET core 3.1 一起使用。当我尝试添加 nuget 包时System.Windows.Interactivity出现错误This package may not be fully compatible with your project。我假设问题是我正在使用的 .NET 版本。有没有办法使它适用于 .NET Core 3.1?

标签: c#.netwpf.net-core-3.1

解决方案


System.Windows.Interactivity 已被 nuget 包替换。

而不是引用您添加包:

Microsoft.Xaml.Behaviors.Wpf

然后,您将需要一个 xmlns。

来自https://devblogs.microsoft.com/dotnet/open-sourcing-xaml-behaviors-for-wpf/ (更多信息参见 )。

迁移步骤如下:

删除对“Microsoft.Expression.Interactions”和“System.Windows.Interactivity”的引用安装“Microsoft.Xaml.Behaviors.Wpf”NuGet 包。XAML 文件 – 替换 xmlns 命名空间“<a href="http://schemas.microsoft.com/expression/2010/interactivity" rel="nofollow noreferrer">http://schemas.microsoft.com/expression/2010/交互性”和“<a href="http://schemas.microsoft.com/expression/2010/interactions" rel="nofollow noreferrer">http://schemas.microsoft.com/expression/2010/interactions“与“ <a href="http://schemas.microsoft.com/xaml/behaviors" rel="nofollow noreferrer">http://schemas.microsoft.com/xaml/behaviors“ C# 文件 – 替换 c# 文件中的使用” Microsoft.Xaml.Interactivity”和“Microsoft.Xaml.Interactions”与“Microsoft.Xaml.Behaviors”<

这是网络核心友好的。

它与 for like 不完全一样,我发现我的一段代码不兼容。不过,对于大多数人来说,这可能不是问题。


推荐阅读