WPF中获取Hwnd与窗体,Uid获取控件
void MapControl_Loaded(object sender, RoutedEventArgs e)
{
this.OnApplyTemplate();
CurrentMapChanged(new DependencyPropertyChangedEventArgs(MapControl.PropertyCurrentMap, "", "")); //
Window parentWindow = Window.GetWindow(this);
IntPtr handle = (new WindowInteropHelper(parentWindow)).Handle;
Console.WriteLine("parentWindow WHnd: " + handle.ToInt32()); HwndSource hwndSource = HwndSource.FromHwnd(handle);
Visual visual = hwndSource.RootVisual; Window window = (Window)visual;
Console.WriteLine("parentWindow WHnd: " + window.Title);
//
String mapUid = Guid.NewGuid().ToString();
this.Uid = mapUid;
//
Console.WriteLine("this control uid: " + this.Uid);
UIElement elem = this.FindUIElementByUid(window, mapUid);
if(elem != null)
{
Console.WriteLine("this control uid: " + elem.Uid);
} } private UIElement FindUIElementByUid(DependencyObject parent, string uid)
{
int count = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < count; i++)
{
UIElement el = VisualTreeHelper.GetChild(parent, i) as UIElement;
if (el == null) continue;
Console.WriteLine("el.Uid: " + el.Uid);
if (el.Uid == uid) { return el; }
UIElement el1 = FindUIElementByUid(el, uid);
if (el1 != null) { return el1; }
}
//
if (parent is ContentControl)
{
UIElement content = (parent as ContentControl).Content as UIElement;
if (content != null)
{
Console.WriteLine("content.Uid: " + content.Uid);
if (content.Uid == uid) return content;
UIElement el1 = FindUIElementByUid(content, uid);
if (el1 != null) { return el1; }
}
} return null;
}
-----------------------------------
WPF中获取Hwnd与窗体,Uid获取控件的更多相关文章
- Windows Presentation Foundation(WPF)中的数据绑定(使用XmlDataProvider作控件绑定)
原文:Windows Presentation Foundation(WPF)中的数据绑定(使用XmlDataProvider作控件绑定) ------------------------------ ...
- WPF中的瀑布流布局(TilePanel)控件
最近在用wpf做一个metro风格的程序,需要用到win8风格的布局容器,只能自己写一个了.效果如下 用法 : <local:TilePanel ...
- [译]- 6-1 排列窗体上的控件(Laying Out Widgets on a Form)
排列窗体上的控件(Laying Out Widgets on a Form) 中英文对照:form(窗体),layout(布局或者排列,意思是进行窗体上控件的排列的过程,如大小位置等) absolu ...
- WPF中不规则窗体与WindowsFormsHost控件的兼容问题完美解决方案
首先先得瑟一下,有关WPF中不规则窗体与WindowsFormsHost控件不兼容的问题,网上给出的解决方案不能满足所有的情况,是有特定条件的,比如 WPF中不规则窗体与WebBrowser控件的兼 ...
- WPF中不规则窗体与WebBrowser控件的兼容问题解决办法
原文:WPF中不规则窗体与WebBrowser控件的兼容问题解决办法 引言 这几天受委托开发一个网络电视项目,要求初步先使用内嵌网页形式实现视频播放和选单,以后再考虑将网页中的所有功能整合进桌面程序. ...
- WPF中制作无边框窗体
原文:WPF中制作无边框窗体 众所周知,在WinForm中,如果要制作一个无边框窗体,可以将窗体的FormBorderStyle属性设置为None来完成.如果要制作成异形窗体,则需要使用图片或者使用G ...
- 根据获取的窗口句柄遍历窗口Edit控件
网上说遍历窗口控件有两种方法: 1),使用EnumChildWindows,没有深究, 学习网址如下:http://blog.sina.com.cn/s/blog_60ac1c4b010116 ...
- jquery获取含有某元素的的控件 “控件名[属性名=值]”
jquery获取含有某元素的的控件 “控件名[属性名=值]”. 如,获取 <input id="${cheackbox}" data-role="icheck&qu ...
- WPF教程十一:简单了解并使用控件模板
WPF教程十一:简单了解并使用控件模板 这一章梳理控件模板,每个WPF控件都设计成无外观的,但是行为设计上是不允许改变的,比如使用Button的控件时,按钮提供了能被点击的内容,那么自由的改变控件外观 ...
- WPF 程序如何跨窗口/跨进程设置控件焦点
原文:WPF 程序如何跨窗口/跨进程设置控件焦点 WPF 程序提供了 Focus 方法和 TraversalRequest 来在 WPF 焦点范围内转移焦点.但如果 WPF 窗口中嵌入了其他框架的 U ...
随机推荐
- Android Monkey使用
Monkey 是什么? Android SDK自带的压力测试工具,也是一个命令行工具.它向系统发送伪随机的用户事件流(如按键输入,触摸屏输入,手势输入等),实现对正在开发的应用程序进行压力测试. (1 ...
- rocksdb和leveldb的bloom filter比较
memtable中的bloom filter rocksdb在memtable中添加了prefix bloom filter,就是对key取prefix,然后把这个prefix加入到bloom fil ...
- SRDC - ORA-1548: Checklist of Evidence to Supply (Doc ID 1682693.1)
SRDC - ORA-1548: Checklist of Evidence to Supply (Doc ID 1682693.1) Action Plan 1. Execute srdc_db_u ...
- Linux与windows的应急响应重点检查项
Linux应急响应重点检查项 用户账号审计: cat /etc/passwd & cat /etc/shadow 在线账户审计: w 登录状况审计: last 空口令账户审计: awk -F: ...
- gn gen ninja
- 遗传算法求解旅行商(TSP)问题 -- python
参考资料: 遗传算法解决TSP旅行商问题(附:Python实现) 遗传算法详解(GA)(个人觉得很形象,很适合初学者) from itertools import permutations impor ...
- Conda和Python的国内安装源
Conda和Python的国内安装源 Windows系统: 更换python国内源的方法. 在"C:\Users[xxxx]\pip\pip.ini"文件中配置如下内容(没有则新建 ...
- keras 学习笔记(二) ——— data_generator
data_generator 每次输出一个batch,基于keras.utils.Sequence Base object for fitting to a sequence of data, suc ...
- rabbit 发送者设置
@Override public void sendUploadOssAndRiskDanger(String uuid, Object objectData) { try { rabbitTempl ...
- 学习:反调试之IsDebuggerPresent
前言:一个反调试IsDebuggerPresent的CreackMe IsDebuggerPresent函数的了解: IsDebuggerPresent 作用 确定调用进程是否由用户模式的调试器调试. ...