首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FrameworkElementFactory信息

FrameworkElementFactory信息
EN

Stack Overflow用户
提问于 2016-02-04 18:53:38
回答 1查看 855关注 0票数 3

我一直在网上寻找关于FrameworkElementFactory类的适当文档,但我似乎找不到适当的教程或有用的信息。

能不能请对这个题目了解得多一点的人给我提供更多的信息?下面是我在THIS问题上所发现的:(感谢鲍勃)

将ItemsSource绑定到myDataGrid

代码语言:javascript
复制
Binding dataGridItemsSourceBinding = new Binding("MyItemsSourceName");
myDataGrid.SetBinding(DataGrid.ItemsSourceProperty, datagridItemsSourceBinding);

创建一个DataGridTemplateColumn

代码语言:javascript
复制
 DataGridTemplateColumn templatecolumn = new DataGridTemplateColumn() {
      Header = "myColumnName", // Add the name of your column here
 };

为在DataCell中显示DataGrid列的值时创建数据模板

代码语言:javascript
复制
 // Displaying Template for when you display the DataCell in the DataGridColumn
 // Create a Data Template for when you are displaying a DataGridColumn
 DataTemplate textBlockTemplate = new DataTemplate();
 // Create a Framework Element for the DataGridColumn type (In this case, a TextBlock)
 FrameworkElementFactory textBlockElement = new FrameworkElementFactory(typeof(TextBlock));
 // Create a Binding to the value being displayed in the DataGridColumn
 Binding textBlockBinding = new Binding("myPropertyName");
 // Assign the Binding to the Text Property of the TextBlock
 textBlockElement.SetBinding(TextBlock.TextProperty, textBlockBinding);
 // Set the DataGridColumn to stretch to fit the text
 textBlockElement.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Stretch);
 // Add the TextBlock element to the Visual Tree of the Data Template
 textBlockTemplate.VisualTree = textBlockElement;
 // Add the Data Template to the DataGridColumn Cell Template
 templatecolumn.CellTemplate = textBlockTemplate;

在编辑DataCell列的DataGrid列中的值时创建数据模板

代码语言:javascript
复制
 // Editing Template for when you edit the DataCell in the DataGridColumn
 // Create a Data Template for when you are displaying a DataGridColumn
 DataTemplate textBoxTemplate = new DataTemplate();
 // Create a Framework Element for the DataGrid Column type (In this case, TextBox so the user can type)
 FrameworkElementFactory textBoxElement = new FrameworkElementFactory(typeof(TextBox));
 // Create a Binding to the value being edited in the DataGridColumn
 Binding textBoxBinding = new Binding("myPropertyName");
 // Assign the Binding to the Text Property of the TextBox
 textBoxElement.SetBinding(TextBox.TextProperty, textBoxBinding);
 // Set the DataGridColumn to stretch to fit the text
 textBlockElement.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Stretch);
 // Add the TextBox element to the Visual Tree of the Data Template
 textBoxTemplate.VisualTree = textBoxElement;
 // Add the Data Template to the DataGridColumn Cell Editing Template
 templatecolumn.CellEditingTemplate = textBoxTemplate;

将已完成的DataGridColumn添加到DataGrid中

代码语言:javascript
复制
 // Add the completed DataGridColumn to your DataGrid
 myDataGrid.Columns.Add(templateColumn);
EN

回答 1

Stack Overflow用户

发布于 2020-04-30 13:46:47

请参阅以下线程:Purpose of using FrameworkElementFactory

目前,微软不建议使用FrameworkElementFactory

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35209273

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档