WPF,以编程方式包装DataGrid单元文本 [英] WPF,DataGrid Cell TextWrapping Programmatically

查看:121
本文介绍了WPF,以编程方式包装DataGrid单元文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用了DataGrid控件.由于我是WPF的新手,所以总会有一些我不理解的东西.我想让DataGrid中的每个单元格在显示Text时显示多行文本.我试图找出解决方案并尝试了一些代码,但没有找到答案.
我发现一种在编辑时使单元格边框变为红色的方法.代码为打击

I used DataGrid Control in my App. since I am new at WPF, there is always somestuff I don''t understand. I want to each cell in DataGrid show Multi line text when dispalying Text is so much. I tried to find out solution and Tried some codes , but did not make it out.
I find a way for make cell border red when it is editing. code as blow

//Cell border turn red when editing
 Style cellStyle = new Style(typeof(DataGridCell));
 Trigger isEditingTrigger = new Trigger();
 isEditingTrigger.Property = DataGridCell.IsEditingProperty;
 isEditingTrigger.Value = true;
 isEditingTrigger.Setters.Add(new Setter(DataGridCell.BorderBrushProperty, Brushes.Red));
 cellStyle.Triggers.Add(isEditingTrigger);

 // Set the cell style for the grid
 this.m_DataGrid.CellStyle = cellStyle;



我尝试使用类似的方法,但失败了.如何设置多行文本显示的TextWrapping属性.

我没有在DataGrid单元中放置任何控件,那么如何使其以编程方式显示多行文本?请注意,我需要编程方法.



I tried to use similar methods, but failed. How can I set TextWrapping property for Multi line text Display.

I did not put any control in my DataGrid cell, so how can I make it display multi line text programmatically ? Please note, I need Programmatic method.

please help!

推荐答案

您需要在单元格中放置一个文本框,然后才能以编程方式设置其文本换行.
You need to put a textbox in your cell, then you can set it''s text wrapping, programatically.


这篇关于WPF,以编程方式包装DataGrid单元文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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