把元素绑定到一起
绑定到非元素对象
1.使用DataContext和Source两种绑定方式及对比:
<StackPanel Margin="10" DataContext="{x:Static SystemFonts.IconFontFamily}"> <TextBlock Margin="5" Text="{Binding Path=Source}"/> <!-- 这一行有所区别,它使用DataContext数据源 --> <TextBlock Margin="5" Text="{Binding Source={x:Static SystemFonts.IconFontFamily}, Path=LineSpacing}"/> <TextBlock Margin="5" Text="{Binding Source={x:Static SystemFonts.IconFontFamily}, Path=FamilyTypefaces[0].Style}"/> <TextBlock Margin="5" Text="{Binding Source={x:Static SystemFonts.IconFontFamily}, Path=FamilyTypefaces[0].Weight}"/> <TextBlock Margin="5" Text="{Binding Source={StaticResource CustomFont}, Path=Source}"/> </StackPanel>
SystemFonts.IconFontFamily:从当前图标标题字体的逻辑字体信息获取字体系列,即当前窗口的字符属性?
效果:
2.使用RelativeSource