【发布时间】:2014-10-10 04:03:30
【问题描述】:
我正在处理一个 WPF 中的小项目,我必须只使用 C# 工作,但几乎没有令人困惑的事情。对齐似乎根本不适用于某些元素,尤其是TextBlock。有时TextAlignment 有效,但仅此而已。我不确定出了什么问题。我使用的部分代码:
public static Canvas buttonRightPanelTile(this Canvas tile)
{
tile.Background = new SolidColorBrush(Color.FromArgb(255,50,50,50));
tile.Height = 100;
tile.Width = 100;
TextBlock title = new TextBlock();
title.Text = "Další\nfunkce";
title.FontSize = Window.Current.Bounds.Height / 36;
title.Foreground = new SolidColorBrush(Colors.White);
title.HorizontalAlignment = HorizontalAlignment.Center;
title.VerticalAlignment = VerticalAlignment.Center;
title.TextAlignment = TextAlignment.Center;
tile.Children.Add(title);
return tile;
}
共有三种对齐方式,它们都不影响平铺中的文本位置。 Tile 本身位于网格单元格中并正确对齐。
提前感谢您的建议。
【问题讨论】: