积极答复者
wpf datagrid 列居中?

问题
答案
-
你好,
你可以再详细描述一下你的问题么? 我不太清楚“列中的内容仍然是左对齐”这句话是什么意思。
如果你是在DataGrid 列中的文字内容没有居中,比如你是用TextBlock去显示内容,那么你可以设置TextBlock内容的居中属性,“TextAlignment="Center"”,参考这个链接(我的第一个回复):
http://social.msdn.microsoft.com/Forums/zh-CN/wpfzhchs/thread/d3f1acd3-914f-4613-98d4-a2e60f0ffee4
编辑:如果你是想让控件居中,你在控件上设置属性,比如:
<TextBlock Name="textBlock" HorizontalAlignment="Center" VerticalAlignment="Center"/>
如果我理解错了,我想你可以给我提供一些简单的代码可以重现的你问题,我想这样对于我解决你的问题会更有帮助。
Best regards,
Sheldon _Xiao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Sheldon _XiaoModerator 2011年2月21日 5:56
-
// 右对齐风格
Style styleRight = new Style(typeof(TextBlock));
Setter setRight = new Setter(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Right);
styleRight.Setters.Add(setRight);foreach (DataGridColumn c in yourDataGrid.Columns)
我猜楼主是要这个类似的东西
{
DataGridTextColumn tc = c as DataGridTextColumn;
if (tc != null)
{
tc.ElementStyle = styleRight;
}
}- 已建议为答案 Jarrey 2011年2月14日 16:02
- 已标记为答案 Sheldon _XiaoModerator 2011年2月21日 5:56
全部回复
-
你好,
你可以再详细描述一下你的问题么? 我不太清楚“列中的内容仍然是左对齐”这句话是什么意思。
如果你是在DataGrid 列中的文字内容没有居中,比如你是用TextBlock去显示内容,那么你可以设置TextBlock内容的居中属性,“TextAlignment="Center"”,参考这个链接(我的第一个回复):
http://social.msdn.microsoft.com/Forums/zh-CN/wpfzhchs/thread/d3f1acd3-914f-4613-98d4-a2e60f0ffee4
编辑:如果你是想让控件居中,你在控件上设置属性,比如:
<TextBlock Name="textBlock" HorizontalAlignment="Center" VerticalAlignment="Center"/>
如果我理解错了,我想你可以给我提供一些简单的代码可以重现的你问题,我想这样对于我解决你的问题会更有帮助。
Best regards,
Sheldon _Xiao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Sheldon _XiaoModerator 2011年2月21日 5:56
-
// 右对齐风格
Style styleRight = new Style(typeof(TextBlock));
Setter setRight = new Setter(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Right);
styleRight.Setters.Add(setRight);foreach (DataGridColumn c in yourDataGrid.Columns)
我猜楼主是要这个类似的东西
{
DataGridTextColumn tc = c as DataGridTextColumn;
if (tc != null)
{
tc.ElementStyle = styleRight;
}
}- 已建议为答案 Jarrey 2011年2月14日 16:02
- 已标记为答案 Sheldon _XiaoModerator 2011年2月21日 5:56
-
你好 shuhang,
由于你没有继续的给我们提供关于你问题状态的信息,因此我们认为你的问题已经得以解决。
我将标记包含有用信息的回复作为答案,这样方便跟你有同样疑惑的成员找到问题的答案。
Best regards,
Sheldon _Xiao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.