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 >

私のプログラムでは、バインディングが存在するかどうかを確認したいと思います。

これはどのように達成する必要がありますか?

編集:はオブジェクトalineのプロパティですDataContext

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 に答える