wpf 绑定非元素对象

 <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自动遍历控件父控件直到找到设置的控件及控件属性。
posted @ 2019-01-16 22:37  吃葡萄不吐葡萄脾  阅读(375)  评论(0编辑  收藏  举报