Detect in XAML broken bindings already at compile

2019-01-15 02:15发布

It is a simple and frequent, I think, scenario - you bind in XAML a dependent 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?

1条回答
狗以群分
2楼-- · 2019-01-15 03:05

you could add the VM-class to your Binding line this:

<DataGrid ItemsSource="{Binding Path=(viewModels:MyViewModel.MyItemsSource)}" />

with:

namespace ViewModels{
    public class MyViewModel{
        public ICollectionView MyItemsSource {get; set;}
    }
}

This shows you BindingErrors at DesignTime

查看更多
登录 后发表回答