已在编译时检测 XAML 中损坏的绑定
问题描述:
我认为这是一个简单而频繁的场景 - 您在 XAML 中将依赖属性绑定到视图模型中的属性,然后在视图模型中重命名该属性,而忘记在 XAML 中重命名它.绑定也被破坏了.
It is a simple and frequent, I think, scenario - you bind in XAML a dependency property to property in the viewmodel and later rename the property in viewmodel and forget to rename it in XAML. So is the binding broken.
有没有办法在编译时就检测到这种破坏的绑定?
Is there a way to detect such a broken bindings already at compile time?
答
您可以将 VM 类添加到您的绑定行中:
you could add the VM-class to your Binding line this:
<DataGrid ItemsSource="{Binding Path=(viewModels:MyViewModel.MyItemsSource)}" />
与:
namespace ViewModels{
public class MyViewModel{
public ICollectionView MyItemsSource {get; set;}
}
}
这向您展示了 DesignTime 的 BindingErrors
This shows you BindingErrors at DesignTime