问题描述
是否有一种方法可以使Silverlight数据网格中的单元格列在C#代码的编辑模式下变为只读模式,而不是将整个数据网格设置为资源文件中的模板?
Is there a way to make column of cells in a Silverlight datagrid be readonly in editmode with C# code instead of setting up a entire datagrid as a template in a resource file?
更新
找到了示例代码-
在通过在线程中途变慢来响应。他有编写为XAML模板的示例代码。
In the response by slhungry midway into the thread. He has example code written as a XAML template. Can you write this in C#?
推荐答案
好吧,您当然可以创建以编程方式在您后面的代码中,并将它们添加到您的 DataGrid
:
Well, you can certainly create DataGridColumns
programmatically in your codebehind and add them to your DataGrid
:
DataGridColumn myColumn = new DataGridColumn();
然后,您可以轻松配置属性:
Then you can easily configure the properties:
myColumn.Header = "tyndall's New Column";
myColumn.IsReadOnly = true; // All cells in column will be readonly
您还可以在后面的代码中以编程方式设置绑定,如果你希望。最后,您可以将此列添加到数据网格:
You can also programmatically set up binding in the codebehind, if you wish. Finally, you can add this column to the datagrid:
myDataGrid.Columns.Add(myColumn);
这是否有助于回答您的问题?
Does this help answer your question?
这篇关于使用C#代码而不是模板XAML进行此操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!