c# - 检查数据绑定(bind)是否存在

标签 c# wpf binding

我正在将一个 xaml 文件动态加载到我的程序中,该文件具有绑定(bind):

<ListView
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Grid.Row="2" BorderBrush="White" Name="ListView1"
    ItemsSource="{Binding Path=line}" HorizontalAlignment="Stretch">
    <ListView.View>
        <GridView>
            <GridViewColumn Header="Lines"
             DisplayMemberBinding="{Binding Path=aline}" />
        </GridView>
    </ListView.View>
</ListView >

在我的程序中,我想检查绑定(bind)是否存在。

这应该如何实现?

编辑:alineDataContext 对象的一个​​属性

最佳答案

您可以像这样检查绑定(bind):

BindingExpression be = BindingOperations.GetBindingExpression(ListView1, ItemsSourceProperty);
return be != null ? "ItemsSource is bound" : "ItemsSource is not bound";

关于c# - 检查数据绑定(bind)是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15116797/

相关文章:

c# - 使用 Vuforia 和 Unity 仅创建一次具有地平面检测的对象

c# - Wpf 绑定(bind)桥

html - 如果来自 HTML 绑定(bind)的对象的 *ngFor Let 对象返回空数组,如何显示占位符

通过 DispatchProxy 进行 C# 日志记录

c# - 如何强制 XDocument 以大写形式输出序言,同时保留缩进和格式?

wpf - 如何强制显示忙碌指示符? (WPF)

.net - 如何使用 double 组的资源制作wpf组合框?

jquery - 函数绑定(bind)和 clone() 函数 - Jquery

c# - 如何在VS2010中打开.ccproj?

c# - 按住按钮重复命令