首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在WPF DataGrid中用自定义DataGridRow替换标准DataGridRow

如何在WPF DataGrid中用自定义DataGridRow替换标准DataGridRow
EN

Stack Overflow用户
提问于 2016-07-27 16:19:58
回答 1查看 309关注 0票数 1

我希望我能用我的自定义版本MyDataGridRow替换DataGrid中的标准DataGridRow

代码语言:javascript
复制
public class MyDataGridRow : DataGridRow
{ ... }

我知道我可以替换标准DataGridRowTemplate,但我想完全替换它,因为它打开了大量的选项,比如引入新的属性、事件等。

我认为这应该是可能的。

你的想法!

与可能的副本相比,这个问题更清楚:How can I add Dependency Property to a DataGridRow WPF。我的问题标题和问题内容更有帮助,也更通用。就像之前发布这个问题一样,我搜索了很多,但什么也找不到。

EN

回答 1

Stack Overflow用户

发布于 2016-07-27 17:01:27

创建一个新的DataGrid并覆盖其GetContainerForItemOverride()方法以返回新的DataGridRowEx

代码语言:javascript
复制
    public class DataGridRowEx : DataGridRow
    {
       // you can add any custom dependency property here
    }

    public class DataGridEx : DataGrid
    {
       //...
       protected override DependencyObject GetContainerForItemOverride()
       {
          return new DataGridRowEx();
       }
    }

答案改编自How can I add Dependency Property to a DataGridRow WPF

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38607531

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档