为什么我会收到这样的信息?
属性 'Dependency' 在此声明类型上无效。它仅对“程序集”声明有效。
public partial class MainWindow : Window
{
private OverviewViewModel _vm;
[Dependency]
public OverviewViewModel VM
{
set
{
_vm = value;
this.DataContext = _vm;
}
}
最佳答案
您可能使用了错误的属性:DependencyAttribute
Indicates when a dependency is to be loaded by the referring assembly [...]
并且只能应用于程序集(而不是像您正在尝试的那样应用于属性),例如:
[assembly: Dependency(/*...*/)]
关于c# - "Attribute ' 依赖 ' is not valid on this declaration type."错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8203632/