C# 数据绑定的几种方式


        <!--第一种默认的方式 指定绑定的数据源和路径-->
        <TextBlock Text="{Binding Source={StaticResource ViewModel}, Path=temp}" ></TextBlock>
        <!--第二种采用Element方式-->
            <TextBlock Text="{Binding ElementName=mainwindow, Path=Title}"></TextBlock>
        <!--第三种采用相对源RelativeSource方式-->
        <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=Window,Mode=FindAncestor},Path=Title }" Foreground="Orange"></TextBlock>
        <!--第4种采用父对象Datacontext进行数据源指定-->
        <TextBlock Text="{Binding Path=value}" DataContext="{StaticResource  ViewModel}"></TextBlock>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM