[英]How to change the orientation of a DataGrid's column header in C#?
I defined a DataGrid
in my WPF and I want to make some column headers appear in vertical form. 我在WPF中定义了一个
DataGrid
,我想使某些列标题以垂直形式显示。 In this other post , this is done via MVVM. 在另一篇文章中 ,这是通过MVVM完成的。 But how can I do this in C# code?
但是,如何在C#代码中执行此操作?
In other words, the method that used MVVM changes the orientation of all column headers. 换句话说,使用MVVM的方法会更改所有列标题的方向。 But I want some of headers to be vertical.
但是我希望某些标题是垂直的。
I kinda asked this question again in here (in another form though). 我在这里再次问了这个问题(虽然是另一种形式)。 The accepted answer solved my problem.
接受的答案解决了我的问题。 I advise the future readers with the same issues to refer to that post .
我建议以后有同样问题的读者参阅该帖子 。 In summary, you have to define multiple styles for the
DataGridColumnHeader
and also assign an event handler to the AutoGeneratingColumn
event. 总之,您必须为
DataGridColumnHeader
定义多种样式,还必须为AutoGeneratingColumn
事件分配事件处理程序。 And then, apply the desired style programmatically. 然后,以编程方式应用所需的样式。
It seems abiding to the MVVM pattern is an overkill. 似乎坚持MVVM模式是过大的选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.