通过后面的代码更新WPF DataGrid列标题文本 [英] Update the WPF DataGrid Column Header Text via code behind

查看:154
本文介绍了通过后面的代码更新WPF DataGrid列标题文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过后面的代码更改WPF DataGrid列标题文本?
i尝试下面的代码,但它不工作。

How can i change the WPF DataGrid Column Header Text via code behind? i tried the code below but its not working.

this.sampleDataGrid.Columns[0].Header = "New Header"; 
this.sampleDataGrid.Refresh();


推荐答案

如果您的DataGridColumn是模板,那么您需要更改其代码中的模板。

If your DataGridColumn is a Template then you need to change its Template in code.

    var template = new DataTemplate();
    template.VisualTree = new FrameworkElementFactory(typeof(TextBlock));
    template.VisualTree.SetValue(TextBlock.TextProperty, "New Header");
    dataGrid.Columns[0].HeaderTemplate = template;

这篇关于通过后面的代码更新WPF DataGrid列标题文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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