我正在尝试将WindowsTerminal.obj.theaterName对齐到中心,但是我不想使用XAML文件。如果我将文本从WindowsTerminal.obj.theaterName更改为“ Cat”,则它将在中间显示该文本。
StackPanel sp = new StackPanel();
if (WindowsTerminal.obj.theaterName.Length > 0)
TextBlock txt = new TextBlock()
{
Text = WindowsTerminal.obj.theaterName,
HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
//TextAlignment = TextAlignment.Center,
Foreground = Brushes.AliceBlue,
Margin = new Thickness(2)
};
sp.Children.Add(txt);
}