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>
  • 相关阅读:
    gradle添加阿里云maven库
    来谈谈MySQL的临时表,到底是个什么东西,以及怎么样产生的
    MySQL优化相关参数--先做个记录,以后可能用得到
    对于join操作,MySQL它是咋做的?
    Linux-常用命令记录
    有时候我们自认为有用的索引却并没有被MySQL选择使用?
    C#趟坑: Wait()线程结束时,会忽略子线程
    初次使用Windbg检查C#程序内存
    性能优化之三:将Dottrace过程加入持续集成
    性能优化之二:结构体类型的性能优化
  • 原文地址:https://www.cnblogs.com/zhuawang/p/2409013.html
Copyright © 2011-2022 走看看