3

我正在将 xaml 文件动态加载到具有绑定的程序中:

<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 >

在我的程序中,我想检查 Binding 是否存在。

这应该如何实现?

编辑:alineDataContext对象的属性

4

2 回答 2

13

您可以检查这样的绑定:

BindingExpression be = BindingOperations.GetBindingExpression(ListView1, ItemsSourceProperty);
return be != null ? "ItemsSource is bound" : "ItemsSource is not bound";
于 2013-02-27T16:29:53.277 回答
-3
if (ListView1.ItemsSource != null)
            Console.WriteLine("Is Bound");
        else Console.WriteLine("Is Not bound");
于 2013-02-27T16:16:54.790 回答