PaN*_*1Me 164 wpf relativesource templatebinding
这两个绑定有什么区别:
<ControlTemplate TargetType="{x:Type Button}">
<Border BorderBrush="{TemplateBinding Property=Background}">
<ContentPresenter />
</Border>
</ControlTemplate>
Run Code Online (Sandbox Code Playgroud)
和
<ControlTemplate TargetType="{x:Type Button}">
<Border BorderBrush="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}">
<ContentPresenter />
</Border>
</ControlTemplate>
Run Code Online (Sandbox Code Playgroud)
?
Gra*_*ath 200
TemplateBinding并不完全相同.MSDN文档通常由那些必须测试单音节SDE关于软件功能的人编写,因此细微差别并不完全正确.
TemplateBindings在编译时根据控件模板中指定的类型进行评估.这允许更快地实例化编译模板.只是在模板绑定中摸索名称,您将看到编译器将标记它.
绑定标记在运行时解析.虽然执行速度较慢,但绑定将解析在模板声明的类型上不可见的属性名称.慢一点,我会指出它的相对类型,因为绑定操作只需要很少的应用程序的cpu.如果你是高速爆破控制模板,你可能会注意到它.
作为一个实践,你可以使用TemplateBinding,但不要担心绑定.
小智 32
TemplateBinding - 比使用常规绑定更具限制性
常规绑定 - 没有TemplateBinding的上述限制
Nir*_*Nir 17
TemplateBinding是使用TemplatedParent绑定的简写,但它不公开Binding类的所有功能,例如,您无法从TemplateBinding控制Binding.Mode.
归档时间: |
|
查看次数: |
101299 次 |
最近记录: |