zoukankan      html  css  js  c++  java
  • WPF几种高级绑定

    (1)Binding  + RelativeSource + AncestorType 模式  , 根据关联源所指定的类型,可动态绑定指定类型的Path属性(Path可以省略)(PS:动态指父级在运行时才可以获取到的属性),例子如下:

    <TextBox x:Name="Date_TextBox" FontFamily="{TemplateBinding FontFamily}" FontSize="{TemplateBinding FontSize}" FontStretch="{TemplateBinding FontStretch}"  
                                         VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                         IsReadOnly="{Binding IsDateReadOnly,RelativeSource={RelativeSource AncestorType=local:FreeDatePicker}}"  BorderThickness="0"  MaxLength="10"
                                         Text="{Binding Path=SelectedDate, Mode=TwoWay,Converter={StaticResource str_mutual_dt},   
                                         StringFormat='yyyy-MM-dd', RelativeSource={RelativeSource AncestorType=DatePicker}}"
                                         KeyDown="Date_TextBox_KeyDown" PreviewMouseDown="Date_TextBox_PreviewMouseDown"
                                         GotKeyboardFocus="Date_TextBox_GotKeyboardFocus" MouseDown="Date_TextBox_MouseDown" GotFocus="Date_TextBox_GotFocus"/>

    (2)TemplateBinding模式(模板绑定),通常在控件模板中——>实现“静态”绑定父级的对应属性(PS:静态指父级在非运行时就具有的属性),例子如下:

    FontSize="{TemplateBinding FontSize}"

    (3)Binding  + RelativeSource + TemplatedParent模式 ,由于关联源指向 “模板的父级”,所以可动态绑定父级的Path属性(Path可以省略),例子如下:

    Source="{Binding NormalImage,RelativeSource={RelativeSource TemplatedParent}}"/>

  • 相关阅读:
    SQL 的单引号转义字符
    Oracle中row_number()、rank()、dense_rank() 的区别
    Hibernate之mappedBy与@JoinColumn
    spring定时任务的注解实现方式
    springmvc常用注解之@Controller和@RequestMapping
    out.print()与out.write()的区别
    idea 中 找不到程序包 的坑
    Thymeleaf学习
    unknow command 'iscan',使用redis desktop manager 无法读取redis存储的数据
    Struts2框架简单介绍
  • 原文地址:https://www.cnblogs.com/changbaishan/p/9172334.html
Copyright © 2011-2022 走看看