带有列标题的gridview的viewmodel c#

带有列标题的gridview的viewmodel c#,第1张

概述我需要一个解决方案. 我需要为网格视图创建一个视图模型.此视图模型应该是强类型的.恩. List<Person> lstPersons=new List<Person>(); 这样的事情.另外,有了这个我应该能够有自定义列标题名称.我可以使用数据注释启用AutoGenerateColumns =“True” 喜欢, class Person{ [DisplayName("Person 我需要一个解决方案.

我需要为网格视图创建一个视图模型.此视图模型应该是强类型的.恩.

List<Person> lstPersons=new List<Person>();

这样的事情.另外,有了这个我应该能够有自定义列标题名称.我可以使用数据注释启用autoGenerateColumns =“True”
喜欢,

class Person{      [displayname("Person name")]      public string name { get; set; }}

这样的事情.但我有2个问题.

>我不知道如何在运行时更改此显示名称.
>我使用telerik RADGrIDVIEw.当我使用autoGenerateColumns =“True”和ShowColumnFooters =“True”时,整个UI都被卡住了.我认为这是telerik控件的错误.所以我必须在XAML中定义所有列,并为每个列添加绑定路径.

无论如何,我认为这可以通过Datatable实现.但我觉得数据表是非常古老的结构和重物.

如何创建viewmodel来实现这一目标?有什么建议 ?

随意提出任何问题.我不确定以上描述对每个人都很清楚.

解决方法 您可以继续在模型上使用displayname属性,但正如您所指出的那样,无法在运行时更改它.为此,请在填充的viewmodel中实现字典

public PeopleGrIDviewmodel{    public ObservableCollection<Person> People;    public Dictionary<string,string> PersonColumnheaders;    public PeopleGrIDviewmodel()    {        // 1. write C# here to snag the property names from the typeof(Person)        // 2. get the displayname attribute value for that property too.        // 3. add the propertyname.ToString() and the displayname string to the dictionary as a key/value pair.        // the result is you have a collection of column headers that start with the defaults from the propertys on the object... but they can be manipulated at run-time,and you don't havem them 100% hard typed like in adcool's example.    }}

我认为显示列页脚交易是你所建议的Telerik问题.

总结

以上是内存溢出为你收集整理的带有列标题的gridview的viewmodel c#全部内容,希望文章能够帮你解决带有列标题的gridview的viewmodel c#所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1126986.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存