获取ItemsControl里面的控件
来源:互联网 发布:网络布线按米收费吗 编辑:程序博客网 时间:2024/05/16 10:04
ItemsControl通过Binding获得数据,每个数据的模板在DataTemplate里面,直接查找DateTemplate里的控件获取不到。可以在ItemsControl的ItemContainerGenerator.StatusChanged时间里通过下列方法获得。
this.itemsControl.ItemContainerGenerator.StatusChanged += ItemContainerGenerator_StatusChanged;private void ItemContainerGenerator_StatusChanged(object sender, EventArgs e){ if (this.itemsControl.ItemContainerGenerator.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated) { this.itemsControl.ItemContainerGenerator.StatusChanged -= ItemContainerGenerator_StatusChanged; Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.DataBind, new Action(DelayedAction)); }}void DelayedAction(){ for (int i = 0; i < this.itemsControl.Items.Count; i++) { var item = this.itemsControl.ItemContainerGenerator.ContainerFromIndex(i); StackPanel stackPanel = VisualTreeExHelper.FindSingleVisualChildren<StackPanel>(item); dateTimePicker.popupCalender1.IsOpen = false; }}
此处的itemsControl为ItemsControl的Name,FindSingleVisualChildren为自己写的搜索子控件的方法。
public static T FindSingleVisualChildren<T>(DependencyObject parentObj) where T : DependencyObject{ T result = null; if (parentObj != null) { for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parentObj); i++) { DependencyObject child = VisualTreeHelper.GetChild(parentObj, i); if (child != null && child is T) { result = child as T; break; } result = FindSingleVisualChildren<T>(child); if (result != null) break; } } return result;}
上面介绍的方法不支持ItemsControl虚拟化。
0 0
- 获取ItemsControl里面的控件
- C#中如何获取ItemsControl的DataTemplate中定义的控件?
- 获取formview里面的控件的值
- 点击item获取里面的控件 ListView
- iOS获取控制器里面的控件
- iOS获取控制器里面的控件
- 自定义控件里面获取控件的高度遇到的问题。
- ItemsControl 的来龙去脉
- ItemsControl 的使用,经典
- 获取子控件里面的输入框 焦点
- 怎么在viewpager中获取子fragment里面的控件
- Delphi 获取 Label 控件里面文字的 Width 宽度
- MFC里面ipaddress控件:获取里面的ip地址为字符串型
- Oncreate里面获取控件宽高。
- 一天一天学 windows phone 控件 之 ItemsControl + ListBox(十五)
- Windows Phone 8.1中数据显示控件基石------ItemsControl
- setWidth()和setHeight()没反应的问题,onCreate()里面获取控件的高度是0
- WPF 点击 datatemplate 里面的控件,获取相应绑定的数据
- mybatis 多参数模糊查询sql
- PCI Local BUS 3.0
- 【View】isShown ()的用法
- GIT工具流程理解及使用说明
- java 调用 .net webservice 示例
- 获取ItemsControl里面的控件
- 在Storyboard中勾选hide bottom bar on push时,底部View下沉的问题
- nginx之nginx.conf配置
- 【J2EE】org.hibernate.exception.SQLGrammarException: could not execute query错误
- 好莱坞经典十大战争电影排行榜 男人必看十大战争片
- GH60--来自geekhack的超强玩具
- 64位win10下openGL的配置---学前准备
- 【最佳实践】观察者模式在android 上的
- 算法导论_第六章_堆排序