查看 Silverlight DataGrid 中派生类变量的顺序
我在使用 DataGrid 的 Visual Studio 2010 (C#) Silverlight 4 项目中遇到以下情况(为简洁起见,这是伪代码):
public class BaseClass {
public string str1;
public string str2;
}
public class DerivedClass : BaseClass {
public string str3;
public string str4;
}
public List<DerivedClass> SetItemSource(List<DerivedClass> list) {
dataGrid.ItemSource = list;
}
当我运行代码时,列按顺序排列:
str3 str4 str1 str2
我希望它们显示为:
str1 str2 str3 str4
有什么办法可以做到这一点吗?我发现 Silverlight DataGrid
非常不灵活。
I have the following situation in a Visual Studio 2010 (C#) Silverlight 4 project using the DataGrid
(this is pseudocode for brevity sake):
public class BaseClass {
public string str1;
public string str2;
}
public class DerivedClass : BaseClass {
public string str3;
public string str4;
}
public List<DerivedClass> SetItemSource(List<DerivedClass> list) {
dataGrid.ItemSource = list;
}
When I run the code, the columns are in the order:
str3 str4 str1 str2
I would like them to display as:
str1 str2 str3 str4
Is there any way of doing this? I am finding the Silverlight DataGrid
to be very inflexible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当我只有一个标准课程时我想更改列的顺序,我使用注释:
我刚刚对派生类进行了尝试:
我的网格列是:str1 str4 str2 str3 正如预期的那样。
[编辑]
需要包含 using 声明:
using System.ComponentModel.DataAnnotations;
使用 [显示...]我真的很喜欢使用 gridview 和 gridview。数据形式。大多数人讨厌讨厌数据形式。我们花了很多令人沮丧的时间来了解如何使其适合/在我们的 LOB 应用程序中工作,但现在它对于 UI 开发人员来说非常强大且快速。
另外 - 如果您不熟悉数据注释,它们绝对是非常棒的。您可以设置诸如 [Required(true)]、[Display(Name="String 3")]、[StringLength(3,ErrorMessage="此字段长度不能超过 3 个字符")]、Range(0,10 ,ErrorMessage="Must be 0-10)")] 等等。验证错误会自动冒泡到 UI。他们在我们的开发过程中节省了大量的时间。
[/编辑]
When I have just a standard class & I want to change the ordering of the columns, I use annotations:
I just tried this with derived classes:
My grid columns were: str1 str4 str2 str3 as expected.
[EDIT]
Needed to include a using declaration:
using System.ComponentModel.DataAnnotations;
to use [Display...]I really enjoy working with both the gridview & the dataform. Most people hate hate hate the dataform. Its taken many frustrating hours to understand how to make it fit/work within our LOB apps, but now it's incredibly powerful and blazing fast for UI dev.
Also - if you're not familiar with Data Annotations, they're absolutely rad. You can set attributes like [Required(true)], [Display(Name="String 3")], [StringLength(3,ErrorMessage="This field can not exceed 3 characters in length")], Range(0,10,ErrorMessage="Must be 0-10)")] etc etc. The validation errors auto bubble up to the UI. They've saved seriously crazy amounts of time in our dev process.
[/EDIT]