zoukankan      html  css  js  c++  java
  • WPF绑定方式

    1.

    stu = new Student();
    Binding binding = new Binding();
    binding.Source = stu;
    binding.Path = new PropertyPath("Name");

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

    或者 

    this.textBoxName.SetBinding(TextBox.TextProperty, new Binding("Name") { Source = stu = new Student() });

    public class Student : INotifyPropertyChanged
        {
            public event PropertyChangedEventHandler PropertyChanged;
            public string _Name;
            public string Name
            {
                get
                {
                    return _Name;
                }
                set
                {
                    _Name = value;
                    if (this.PropertyChanged != null)
                    {
                        this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Name"));
                    }
                }

            } 

    2.把控件作为Binding源、Binding标记拓展

    <TextBox x:Name="textBox1" Text="{Binding Value,ElementName=slider1}" BorderBrush="Black" Margin="5"></TextBox>
    <Slider x:Name="slider1" Maximum="100" Minimum="0" Margin="5"></Slider>

    3. this.listBoxStuents.ItemsSource = stuList;//List<T>集合

     <StackPanel x:Name="stackPanel" Background="LightBlue">

            <TextBlock Text="Student ID:" FontWeight="Bold" Margin="5"></TextBlock>
            <TextBox x:Name="textBoxId" Margin="5"></TextBox>
            <TextBlock Text="Student List:" FontWeight="Bold" Margin="5"></TextBlock>
            <ListBox x:Name="listBoxStuents" Height="110" Margin="5">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Id}" Width="30"></TextBlock>
                            <TextBlock Text="{Binding Name}" Width="60"></TextBlock>
                            <TextBlock Text="{Binding Age}" Width="30"></TextBlock>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </StackPanel>
  • 相关阅读:
    常见常用的CSS
    Js删除数组函数
    使用CSS让多出来的字变为省略号
    CSS缩写的样式
    mac下安装nginx
    ubuntu下程序员常用命令大全
    vue.js实现瀑布流之vue-waterfall-easy
    vue.js常见的报错信息及其解决方法的记录
    laravel5.4生成验证码
    java算法之超级丑数
  • 原文地址:https://www.cnblogs.com/zhuawang/p/2409013.html
Copyright © 2011-2022 走看看