首页 新闻 搜索 专区 学院

wpf DataGrid中怎么获取DataTemplate里的控件。。

0
悬赏园豆:5 [已解决问题] 解决于 2009-12-07 13:40

<my:DataGridTemplateColumn  Header="特价日">
                                        <my:DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <ComboBox Name="cbName" SelectedIndex="0" ItemsSource="{Binding}">
                                                </ComboBox>
                                            </DataTemplate>
                                        </my:DataGridTemplateColumn.CellTemplate>
                                    </my:DataGridTemplateColumn> 

获取COMBOX这个控件

问题补充: 后台代码获取
纯情小火鸡的主页 纯情小火鸡 | 初学一级 | 园豆:154
提问于:2009-12-04 16:57
< >
分享
最佳答案
0

(控件类型)DataGrid。FinContrl(“控件名称”)

收获园豆:5
苏飞 | 老鸟四级 |园豆:2024 | 2009-12-05 17:41
如果不能这样找到 //ContentPresenter pr=(ContentPresenter)this.dgSpecialPrice.Template; //ComboBox cb = this.FindName("cbName") as ComboBox; //DataGridBoundColumn list = (DataGridBoundColumn)dgSpecialPrice.ItemContainerGenerator.ContainerFromItem(dgSpecialPrice.Items.CurrentItem); //ContentPresenter myContentPresenter = FindVisualChild<ContentPresenter>(list); //DataTemplate myDataTemplate = myContentPresenter.ContentTemplate; //ComboBox cb = (ComboBox)myDataTemplate.FindName("cbName", myContentPresenter); private childItem FindVisualChild<childItem>(DependencyObject obj)where childItem : DependencyObject { for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++) { DependencyObject child = VisualTreeHelper.GetChild(obj, i); if (child != null && child is childItem) return (childItem)child; else { childItem childOfChild = FindVisualChild<childItem>(child); if (childOfChild != null) return childOfChild; } } return null; } 我是这样实现的
纯情小火鸡 | 园豆:154 (初学一级) | 2009-12-07 13:36
其他回答(1)
0

你敢不敢换个行呀

卧龙学子 | 园豆:202 (菜鸟二级) | 2015-04-03 16:14
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册