zoukankan      html  css  js  c++  java
  • 绑定

    BindsDirectlyToSource

    主要用于ObjectDataProvider,绑定到provide自身,而不是provider所包含的对象

    <Window.Resources>
        <ObjectDataProvider x:Key="odp"  ObjectType="{x:Type local:Calculator}" MethodName="Add">
                <ObjectDataProvider.MethodParameters>
                    <system:String>0</system:String>
                    <system:String>0</system:String>
                </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
      </Window.Resources>
       <StackPanel>
                <TextBox x:Name="textBox1" Margin="5" Text="{Binding Source={StaticResource odp}, Path=MethodParameters[0], BindsDirectlyToSource=true, UpdateSourceTrigger=PropertyChanged}" />

    OneWayToSource 绑定与 OneWay 绑定相反;当目标属性更改时,它会更新源属性。OneWay隐式只读,OneWayToSource隐式只写。 ItemsSource 属性默认支持 OneWay 绑定

    OneTime 使源属性初始化目标属性,但不传播后续更改。它在源值不更改的情况下提供更好的性能

    BindingProxy

    in some cases the DataContext is not accessible: it happens for elements that are not part of the visual or logical tree.
    The solution to our problem is actually quite simple, and takes advantage of the Freezable class. 

    Freezable objects can inherit the DataContext even when they’re not in the visual or logical tree. 

    public class BindingProxy : Freezable
        {
            protected override Freezable CreateInstanceCore()
            {
                return new BindingProxy();
            }
    
            public object Data
            {
                get { return (object)GetValue(DataProperty); }
                set { SetValue(DataProperty, value); }
            }
    
            public static readonly DependencyProperty DataProperty =
                DependencyProperty.Register("Data", typeof(object), typeof(BindingProxy), new UIPropertyMetadata(null));
        }

    We can then declare an instance of this class in the resources of the DataGrid, and bind the Data property to the current DataContext:

    <DataGrid.Resources>
        <local:BindingProxy x:Key="proxy" Data="{Binding}" />
    </DataGrid.Resources>
    The last step is to specify this BindingProxy object (easily accessible with StaticResource) as the Source for the binding:
    <DataGridTextColumn Header="Price" Binding="{Binding Price}" IsReadOnly="False"
                        Visibility="{Binding Data.ShowPrice,
                            Converter={StaticResource visibilityConverter},
                            Source={StaticResource proxy}}"/>

    DataGrid 只读模式的绑定触发

    In a DataGrid the bindings do not get updated until you end editing of the row. Try adding UpdateSourceTrigger=PropertyChanged to the RadioButton's binding expression to update bindings immediately:

    <RadioButton Name="rbM" GroupName="CMGrp" IsChecked="{Binding Path=SELECT, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

  • 相关阅读:
    backbone.js初体验--构建简单分页应用时踩到的坑
    使用r.js打包js文件
    javascript原型式继承
    javascript浮点数运算修正
    javascript对象的浅复制与深复制
    javascript类式继承
    初识requirejs(二)
    标准版SCADA 上线了~~ 三菱 Fanuc 广数 华中 西门子 HAAS等等 可以做到一套程序通用,采集所有CNC PLC
    KepServerEX读写三菱PLC,车间现场测试记录,带你了解【数据采集的困境】的前世与今生
    Mitsubishi (三菱) Fanuc(发那科),CNC,网口数据采集,NC程序下发(其它品牌CNC,哈斯 马扎克 兄弟等,正在开发中)
  • 原文地址:https://www.cnblogs.com/yetsen/p/13549873.html
Copyright © 2011-2022 走看看