有沒有辦法來垂直對齊文本(即中心)在運行時創建一個WPF按鈕裏面,我已經試過:如何在運行時在一個WPF按鈕中居中對齊文本?
代碼段
Button btn = new Button();
Style style = this.FindResource("ButtonStyle1") as Style;
btn.Style = style;
TextBlock txtTblNme = new TextBlock();
txtTblNme.Text = Convert.ToString(Tbl.SelTblNme(i));
txtTblNme.TextAlignment = TextAlignment.Center;
txtTblNme.VerticalAlignment = VerticalAlignment.Center;
txtTblNme.HorizontalAlignment = HorizontalAlignment.Stretch;
btn.Content = txtTblNme;
如果你不使用ButtonStyle1會發生什麼?在我的電腦上它可以工作,文本垂直對齊按鈕 – Klaus78 2012-04-26 07:14:42