Do this in C# code instead of template XAML

孤街浪徒 提交于 2020-01-06 19:34:53

问题


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?

UPDATE
Found an example piece of code - http://forums.silverlight.net/forums/p/17483/58189.aspx

In the response by slhungry midway into the thread. He has example code written as a XAML template. Can you write this in C#?


回答1:


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?



来源:https://stackoverflow.com/questions/3635947/do-this-in-c-sharp-code-instead-of-template-xaml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!