使用C#代码而不是模板XAML进行此操作 [英] Do this in C# code instead of template XAML

查看:124
本文介绍了使用C#代码而不是模板XAML进行此操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以使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?

更新

找到了示例代码-
http://forums.silverlight.net/forums/p/17483/58189.aspx

在通过在线程中途变慢来响应。他有编写为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#?

推荐答案

好吧,您当然可以创建 DataGridColumns 以编程方式在您后面的代码中,并将它们添加到您的 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进行此操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆