How can I find all the target dependency properties bound to a property?

For instance:

<UserControl>
    <TextBox Text="{Binding Path=Foo, Mode=TwoWays}"/>
    <TextBlock Text="{Binding Path=Foo}"/>
</UserControl>

In the code, you can find a list of dependency properties that use the Foo property as a source?

+3
source share
2 answers

It really depends, and as HB points out, but it would be very intense even in “mild” cases.

In your example, assuming you can get into Bindings, you can check the Path property and see if it refers to your Foo property. But there are times when it does not work. For example, binding, for example {Binding Path=DataContext.Foo}. A path can be much more complicated than individual property names.

, DataContext , . , DataTemplate, . , :

<UserControl>
    <ContextControl Content="Test">
        <ContextControl.ContentTemplate>
            <DataTemplate>
                <TextBox Text="{Binding Path=Foo, Mode=TwoWay}"/>
            </DataTemplate>
        </ContextControl.ContentTemplate>
    </ContextControl>
</UserControl>

Foo "Test", . , Source, ElementName RelativeSource Binding.

, DataContext , , , .

-, VisualTreeHelper, . .

. DependencyProperty.

, GetBindingExpression, BindingExpression. , ParentBinding.

.

+2

, , , , .

+1

All Articles