首页 新闻 会员 周边 捐助

wpf 数据模板后台绑定事件的问题

0
悬赏园豆:5 [已关闭问题] 关闭于 2016-06-24 09:17

GridViewColumn column = new GridViewColumn();
GridViewColumnHeader h = new GridViewColumnHeader();
h.Content = "??????";
h.Tag = "*******";
column.Header = h;
DataTemplate dt = new DataTemplate();
FrameworkElementFactory fef = new FrameworkElementFactory(typeof(CheckBox));
Binding binding = new Binding();
binding.Path = new PropertyPath("MarketIndicator");
fef.SetBinding(CheckBox.ContentProperty, binding);
fef.SetValue(CheckBox.ForegroundProperty, Brushes.White);
dt.VisualTree = fef;
column.CellTemplate = dt;
//-----------------------网上找的这段代码,是可以通过fef.SetValue来给CheckBox属性赋值,
但是如果想为上层控件添加事件,fef.SetValue(CheckBox.ClickEvent,?); ?位置放什么才对呢,显示是object可是放上我写的事件函数名,或者放委托都是错误呢???,求如何给上层元素添加事件??

WPF
昨天梦想的主页 昨天梦想 | 初学一级 | 园豆:191
提问于:2016-04-05 10:56
< >
分享
所有回答(1)
0
DataGridTextColumn txtcl = null;
            Binding binding = null;
            DataTable student = ClassBLL.DormitoryBll.TableFeilds("V_Student");//获取视图字段

            //-------------添加选择列
            DataGridTemplateColumn dgtc = new DataGridTemplateColumn();
            dgtc.Header = "选择";
            DataTemplate dt = new DataTemplate();
            //定义子元素
            FrameworkElementFactory fef = new FrameworkElementFactory(typeof(CheckBox));
            binding = new Binding("ID");
            fef.SetValue(CheckBox.TagProperty, binding);
            fef.SetValue(CheckBox.ForegroundProperty, Brushes.Red);
            //为每个对象添加事件
            fef.AddHandler(CheckBox.ClickEvent, new RoutedEventHandler(Row_Checked));
            dt.VisualTree = fef;//添加子元素
            dgtc.CellTemplate = dt;
            dgrid.Columns.Add(dgtc);//将第一列添加到数据表

 

昨天梦想 | 园豆:191 (初学一级) | 2016-06-24 09:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册