WPF学习笔记-绑定非元素对象

WPF学习笔记-绑定非元素对象
<Window x:Class="WPFdemo6.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WPFdemo6"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <FontFamily x:Key="ZY">Resources TextBlock</FontFamily>
    </Window.Resources>
    <Grid Name="Grid">
        <WrapPanel Name="WrapPanel">
            <StackPanel Name="StackPanel">
                <!--绑定系统字体信息-->
                <TextBlock Name="TextBlock1"  Height="20" Width="200" Text="{Binding Source={x:Static SystemFonts.IconFontFamily},Path=Source}"></TextBlock>
                <!--绑定资源信息-->
                <TextBlock Name="TextBlock2" Height="20" Width="200" Text="{Binding Source={StaticResource ZY},Path=Source}"></TextBlock>
                <!--绑定上层元素信息 Mode=FindAncestor 匹配的第一个 AncestorLevel=1-->
                <TextBlock Name="TextBlock3" Height="20" Width="200" Text="{ Binding  Path=Name,RelativeSource={ RelativeSource Mode=FindAncestor,AncestorType={x:Type StackPanel},AncestorLevel=1}}"></TextBlock>
                <!--其他几种待补充-->
            </StackPanel>
        </WrapPanel>
    </Grid>
</Window>
View Code

 

WPF学习笔记-绑定非元素对象

上一篇:Unicode 和 UTF-8 有什么区别


下一篇:第三节:Windows平台部署Asp.Net Core应用(基于IIS和Windows服务两种模式)