<Grid> <StackPanel Margin="5" Name="cooos" DataContext="{x:Static SystemFonts.IconFontFamily}"> <TextBlock Text="{Binding Path=Source }"></TextBlock> <TextBlock Text="{Binding Source={StaticResource ccc}, Path=Source}"></TextBlock> <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=StackPanel,Mode=FindAncestor,AncestorLevel=1},Path=Name}"> </TextBlock> <TextBox Background="{Binding Source={StaticResource test1} }" ></TextBox> </StackPanel> </Grid>
DataContext,Source,RelativeSource用法
x:Static引用系统资源,Source={StaticResource ccc}引用自定义资源
RelativeSource自动遍历控件父控件直到找到设置的控件及控件属性。