• WPF之元素绑定


    元素绑定——WPF从源对象提取一些信息,并用这些对象设置目标对象的属性。

    绑定的模式:

    OneWay  

    当源属性变化时更新目标属性
    TwoWay  当源属性变化时更新目标属性,并且当目标属性变化时同时更新源属性
    OneTime 最初根据源属性的值设置目标属性
    OneWayToSource 与OneWay类型相似,但方向相反
    Default 依赖于目标属性

     

     

     

     

     

    窗体如下:

    在xmal文件中进行绑定

      <StackPanel>
            <Slider Name="slider1" Minimum="0" Maximum="40" TickFrequency="1" Value="20" TickPlacement="TopLeft"></Slider>
            <TextBlock Name="textBlock" Text="Lynn Test"
                      FontSize="{Binding Source=slider1,Path=Value,Mode=TwoWay}"  
                       />
            <Button Name="button1" Content="Change TextBlock FontSize" Click="button1_Click" Height="50"/>
            <Button Name="button2" Content="" Height="45"/>
        </StackPanel>
    

    在代码中进行绑定

    private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                Binding bing = new Binding();
                bing.Source = this.slider1;
                bing.Path = new PropertyPath("Value");
                bing.Mode = BindingMode.TwoWay;
    
                this.textBlock.SetBinding(TextBlock.FontSizeProperty, bing);
            }
    

      

  • 相关阅读:
    Memo
    list查询记录时页面变成空白
    get the mail ids of the group members
    ui action(server side) change column value
    catalog item 时间按照指定形式输出
    select box 联动
    lookup select box和select box 联动
    函数二--递归
    函数一
    指针3
  • 原文地址:https://www.cnblogs.com/LynnXue/p/12637373.html
Copyright © 2020-2023  润新知