WPF RelativeSource的使用
<Window x:Class="XamlTest.Window15"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window15" Height="300" Width="300">
<Grid>
<StackPanel Name="sp1">
<Grid Name="gd1">
<StackPanel Name="sp2">
<Grid Name="gd2">
<!--<TextBlock Text="{Binding RelativeSource={RelativeSource AncestorLevel=1, AncestorType=StackPanel, Mode=FindAncestor}, Path=Name}"></TextBlock>-->//xaml实现
<TextBlock Name="txt"></TextBlock>
</Grid>
</StackPanel>
</Grid>
</StackPanel>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace XamlTest
{
/// <summary>
/// Interaction logic for Window15.xaml
/// </summary>
public partial class Window15 : Window
{
public Window15()
{
InitializeComponent();
Binding b = new Binding();
b.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(StackPanel), 1);
b.Path = new PropertyPath("Name");
txt.SetBinding(TextBlock.TextProperty, b);
}
}
}
WPF RelativeSource的使用的更多相关文章
- [WPF系列-高级TemplateBinding vs RelativeSource TemplatedParent]
What is the difference between these 2 bindings: <ControlTemplate TargetType="{x:Type Button ...
- 在WPF中如何使用RelativeSource绑定
在WPF绑定的时候,指定绑定源时,有一种办法是使用RelativeSource. 这种办法的意思是指当前元素和绑定源的位置关系. 第一种关系: Self 举一个最简单的例子:在一个StackPanel ...
- WPF利用通过父控件属性来获得绑定数据源RelativeSource
WPF利用通过父控件属性来获得绑定数据源RelativeSource 有时候我们不确定作为数据源的对象叫什么名字,但知道作为绑定源与UI布局有相对的关系,如下是一段XAML代码,说明多层布局控件中 ...
- WPF绑定のRelativeSource
在WPF绑定的时候,指定绑定源时,有一种办法是使用RelativeSource. 这种办法的意思是指当前元素和绑定源的位置关系. 第一种关系: Self 举一个最简单的例子:在一个StackPanel ...
- 【WPF】WPF通过RelativeSource绑定父控件的属性
1.后台代码实现绑定父控件的属性 RelativeSource rs = new RelativeSource(RelativeSourceMode.FindAncestor); //设定为离自己控件 ...
- WPF的控件Binding的ElementName/RelativeSource具体用法
<TextBlock Name="_txtSickBedNo" FontStyle="Normal" Foreground="Black&quo ...
- RelativeSource.TemplatedParent 属性wpf
今天看到这一句代码时候,自己只是知道绑定了,可是不知道绑定了什么啊 就去查了一下,后来说的好像是绑定的TemplateParent返回的 一个值.可是这是为什么呢, 有的说是绑定的是一个资源. 下面有 ...
- WPF绑定数据源之RelativeSource
Command="{Binding ConfirmRegisterCommand}" CommandParameter="{Binding RelativeSource= ...
- WPF教程(四)RelativeSource属性
我们进行Bingding时,如果明确知道数据源的Name,就能用Source或者ElementName进行绑定,但是有时候我们需要绑定的数据源可能没有明确的Name,此时我们就需要利用Bingding ...
随机推荐
- Java Queue的使用
Queue的成员函数 add 增加一个元索 如果队列已满,则抛出一个IIIegaISlabEepeplian异常 rem ...
- AOP概述:
AOP可以在不修改源代码的情况下,对程序进行增强. AOP面向切面进行编程,Spring将AOP引入到框架中,但是也需要遵守AOP联盟的规范. 通过预编译的方式和运行期动态代理实现程序功能的同意维护的 ...
- CCPC2016长春站打铁记
Day0 晚上到的长春.很冷.到了宾馆.放了行李.然后就去吃了点火锅.很好吃.在福建吃的都没有酱.但是回去后有点拉肚子..几个队友也有同样的反应.路过了吉大.拍了一张照片.哎.压力好大. Day1 来 ...
- ExtJs中window用法
1.显示html var htmlTitle = "<div style='width:100%;text-align:center'>"; var fruits = ...
- https://github.com/zhangxianyi/Source-Insight-Plugin
https://github.com/zhangxianyi/Source-Insight-Plugin
- "Swift"编程语言
来自英文文档.百度翻译以及自己没过4级的渣渣英语功底,为了自己以后看起来方便 About Swift 关于"海燕" IMPORTANT 重要 This is a prelimina ...
- JFinal redis cluster集群插件
JFinal redis cluster集群插件 JFinal 框架到了2.1版本号,可是依旧仅仅支持redis的主从集群,没有看到Cluster集群的插件.笔者照着主从的插件方式,改了改,实现了个简 ...
- SpringMVC中支持多视图解析
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/suo082407128/article/details/70173301 在SpringMVC模式当 ...
- Framework for Graphics Animation and Compositing Operations
FIELD OF THE DISCLOSURE The subject matter of the present disclosure relates to a framework for hand ...
- NET C#转Java
NET C#转Java .NET C#转Java没那么难,都是面向对象的语言,而且语法还是相似的,先对比一下开发环境,再到Servlet,再到MVC,都是一样一样的,只是JAVA的配制项比较多而已,只 ...