Binding.BindsDirectlyToSource Property

 

<Grid.Resources>
            <local:StrAndDoubleConverter x:Key="cvt"/>
            <ObjectDataProvider x:Key="dprd" ObjectType="{x:Type local:Demo}"
                                MethodName="GetMin">
                <ObjectDataProvider.MethodParameters>
                    <sys:Double>0</sys:Double>
                    <sys:Double>0</sys:Double>
                </ObjectDataProvider.MethodParameters>
            </ObjectDataProvider>
</Grid.Resources>

 

            <TextBox Grid.Row="0" Grid.Column="1" Margin="4" Text="{Binding Source={StaticResource dprd},BindsDirectlyToSource=True,Mode=TwoWay,Path=MethodParameters[0],Converter={StaticResource cvt},UpdateSourceTrigger=PropertyChanged}"/>
            <TextBox Grid.Row="1" Grid.Column="1" Margin="4" Text="{Binding Source={StaticResource dprd},BindsDirectlyToSource=True,Mode=TwoWay,Path=MethodParameters[1],Converter={StaticResource cvt},UpdateSourceTrigger=PropertyChanged}"/>

 

<TextBlock Grid.Row="1" Margin="5">
            <Run Text="较小的那个数:"/>
            <Run Text="{Binding Source={StaticResource dprd},Mode=OneWay}" Foreground="DarkGreen" FontSize="18"/>
        </TextBlock>

 

The normal behavior (when this property is false) includes special treatment for DataSourceProvider objects.

In this case, the binding engine evaluates the Path relative to the object obtained from the Data property. In addition,

the binding listens for the DataChanged event and reacts accordingly.

Setting this property to true overrides this behavior and gives the binding access to properties of the DataSourceProvider object itself.

 

说明: BindsDirectlyToSource 指对Source是如何计算的  false  指  绑定的是Source 返回结果,  True 指 绑定的是Source 所对应的这个对象。

 

posted @ 2018-07-19 09:43  高_山_流_水  阅读(312)  评论(0)    收藏  举报