将对象与居中对齐

时间:2019-02-05 16:58:31

标签: c# wpf

我正在尝试将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);


                }

0 个答案:

没有答案