Wpf学习

源代码的分支:

  1. properties:程序用到的资源(如:图片,图标,静态的字符串)和配置文件

  2. References(引用):

  3. App.xaml:程序的主体

  4. Windows.xaml:程序的主窗体

     

 

Binding绑定TextBox

            binding binding = new Binding();

            binding.Source = stu;

            binding.Path = new PropertyPath("Name");        //为binding指定访问路径

            BindingOperations.SetBinding(this.textBox1, TextBox.TextProperty, binding);

            //第一个参数:指定binding的目标,第二个参数:为binding指明传达目标的那个属性,第三个参数,binding实例

 

控件作为binding源

        <TextBox Text="{Binding ElementName=slider1,Path=Value,Mode=OneWay}" Margin="5"></TextBox>

        <Slider x:Name="slider1" Margin="5"/>

        ------->与以下c#代码等同

        this.textbox.setBinding(TextBox.TextProperty,new Binding("Value") {ElementName="slider1"})

 

Mode类型:

        OneWay:单向

        TwoWay:双向

        Default:根据情况而定,如是可编辑(如Textbox.Text属性),默认为TwoWay,如是不可编辑的(TextBlock.Text属性)则默认为单项模式

        OnTime:

        OnWayToSource:

 

UpdateSourceTrigger属性

        PropertyChanged:实时改变

        LostFocus:焦点离开后改变

        Explicit:

    

取TextBox的第3个字符:path=Text[3]

 

posted @ 2017-11-29 21:02  BeeSnow  阅读(181)  评论(0编辑  收藏  举报