在编译时已在XAML中检测到已断开的绑定 [英] Detect in XAML broken bindings already at compile time

查看:86
本文介绍了在编译时已在XAML中检测到已断开的绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这是一个简单且频繁的场景-您在XAML中将一个依赖属性绑定到视图模型中的属性,然后在视图模型中重命名该属性,而忘记了在XAML中对其重命名.绑定也被破坏了.

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?

推荐答案

您可以通过以下方式将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;}
    }
}

这向您显示了设计时的BindingErrors

This shows you BindingErrors at DesignTime

这篇关于在编译时已在XAML中检测到已断开的绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆