[英]Setting of Textbox.TextAlignment in code-behind of WPF produces wrong results
我正在使用VS 2015編寫WPF應用程序。在我的代碼中,我像這樣設置FrameworkElements /控件的屬性:
if (textblock.GetType().GetProperty("TextAlignment") != null)
textblock.GetType().GetProperty("TextAlignment").SetValue(textblock, value);
在這種情況下,FrameworkElement類型的變量textBlock包含一個TextBlock控件。 當我為每個示例設置值= HorizontalAlignment.Center並檢查其后的屬性時,它包含“ HorizontalAlignment.Right”。
為什么會發生這種情況,我該怎么辦?
預先感謝,帕特里克
我發現了! TextAlignment屬性具有自己的TextAlignment枚舉。 當我嘗試設置HorizontalAlignment.Center時,結果為TextAlignment = Right。 但是使用Textalignment = TextAlignment.Center,結果是正確的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.