文章转载自:

[Silverlight] Silverlight中访问父对象

http://bbs.blueidea.com/thread-2964806-1-1.html

当前一个需求是一个UserControl内嵌套了子的UserControl,子需要调用父的里面的方法。

主要用到的代码:

public static class TreeHelper
{
public static T FindParentByType<T>(this DependencyObject child) where T : DependencyObject
{
Type type = typeof(T);
DependencyObject parent = VisualTreeHelper.GetParent(child); if (parent == null)
{
return null;
}
else if (parent.GetType() == type)
{
return parent as T;
}
else
{
return parent.FindParentByType<T>();
}
}
}

调用方法:this就是当前对象,找到父UserControl就是RiverPage这个对象

RiverPage parent = this.FindParentByType<RiverPage>();

silverlight 子UserControl获取父UserControl的更多相关文章

  1. frameset子窗口获取父窗口失败原因?

    报错信息: arrow.html:44 Uncaught SecurityError: Blocked a frame with origin "null" from access ...

  2. js 在iframe子页面获取父页面元素,或在父页面 获取iframe子页面的元素的几种方式

    用JS或jquery访问页面内的iframe,兼容IE/FF 注意:框架内的页面是不能跨域的! 假设有两个页面,在相同域下. index.html 文件内含有一个iframe: XML/HTML代码 ...

  3. window.open子窗口获取父窗口的值

    //子窗口获取父窗口id的值 window.opener.document.getElementById("id").value; //子窗口调用父窗口的函数 window.ope ...

  4. iframe父页面获取iframe子页面的元素 与 iframe子页面获取父页面元素

    一.在iframe子页面获取父页面元素代码如下:$('#objld', parent.document); 二.在父页面获取iframe子页面的元素代码如下:$("#objid", ...

  5. jQuery子页面获取父页面元素

    $("input[type='checkbox']:checked",window.opener.document);//适用于打开窗口的父页面元素获取 $("input ...

  6. iframe子页面获取父页面元素的方法

    在iframe子页面获取父页面元素 代码如下: $.('#objld', parent.document); 在父页面获取iframe子页面的元素 代码如下: $("#objid" ...

  7. C#如何在子窗体获取父窗体的实例

    在子窗体可以使用this.Owner来获取父窗体的实例

  8. js子页面获取父页面数据

    做页面预览的时候,数据没有存入数据库,但是要打开一个页面进行预览,询问众大婶,原来是这样来做. 1.父页面 <input type="text" id="name& ...

  9. 子组件获取父组件数据 propsDown, 父组件获取子组件数据 eventUp

    (一) popsDowm 三种方法获取父组件数据:被动获得(1):主动获取(2). 1.被动获得: 父组件:v-bind: 绑定变量参数和方法参数:子组件:props 接收参数.可以在模板中直接使用也 ...

随机推荐

  1. vs2010 静态使用 opencv 2.46 库

    下载opencv2.46的库,假设解压到OpenCV246,设置如下: 在工程的c++的include目录下添加:OpenCV246\opencv\build\include 在工程的c++的lib目 ...

  2. linux 常见名词及命令(一)

    linux  PK  wondows 稳定且有效率.免费或少许费用.漏洞少且修补快.多任务多用户. 安全的用户及文件权限策略.适合小内核程序的嵌入系统.相对不耗资源. 热门的开源系统 红帽企业系统(R ...

  3. CodeForces 599C Day at the Beach

    预处理一下i到n的最小值. #include<cstdio> #include<cstring> #include<cmath> #include<algor ...

  4. Reverse Nodes in k-Group (链表)

    Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If ...

  5. BZOJ 1798:

    6:       LAZY 线段树有乘法的更新    #include <cstdio> #include <cstring> #include <algorithm&g ...

  6. grunt安装,配置记录

    进了新的公司,需要重构一个项目,从头开始.本人患懒癌已久,一直没有写博客的打算,也是因为资质还比较浅,写不出什么富有涵养的内容,后来想了想,就当自己的笔记吧.这次从新开始,未尝不是一个博客开始的好时机 ...

  7. C\C++中strcat()函数、sprintf函数

    http://blog.csdn.net/smf0504/article/details/52055971 http://c.biancheng.net/cpp/html/295.html

  8. SpringBoot初始教程之项目结构(一)

    SpringBoot初始教程之项目结构 1 简介 spring Boot makes it easy to create stand-alone, production-grade Spring ba ...

  9. react-container-query

    1.媒体查询 响应式组件 2.使用方法 (1)引入 import { ContainerQuery } from 'react-container-query'; (2)规定屏幕尺寸 /** * 媒体 ...

  10. Mongodb for PHP教程之管理工具

    1:下面的事情应该是PHP程序员应该了解的,更详细的参考可以百度谷歌之 mongodb PHP官方文档http://us.php.net/manual/en/book.mongo.php 1.Mong ...