在对WPF编程中,常常会使用到标记扩展,属性在处于未知状态时,需要引用到一些特定的资源,就要将属性绑定到资源对象。它能够实现页面赋值、资源引用、类型转换等操作。
常用的标记扩展
- Binding(XAML载入时,将数据绑定到XAML对象)
- StaticResource(引用数据字典中定义的静态资源)
- RelativeSource(对特定数据源绑定)
- TemplateBinding(XAML页面中对象模板绑定调用)
Binding
ElementName用于绑定到xaml界面设计中添加的其它控件对象refButton
path路径填写的就是refButton的具体属性
在第二个Button中Width、Heigh、Background都绑定了第一个Button里面Width、Height、Background属性的值
<StackPanel>
<Button x:Name="refButton" Width="100" Height="50" VerticalAlignment="Bottom" Background="GreenYellow"></Button>
<Button Content="button" VerticalAlignment="Top" Width="{ Binding ElementName=refButton,Path=Width}" Height="{ Binding ElementName=refButton,Path=Height}"
Background="{ Binding