2010-06-23 36 views
2

當WPF應用程序啓動時,它會應用一些標準設置來確定文本和數字的外觀。有沒有辦法讓我以編程方式更改這些默認設置?如何更改WPF中的排版默認值?

例如,FontNumeralAlignment documentation on MSDN指出值「Normal」意味着「使用默認數字對齊」。在我的系統上,這似乎默認爲FontNumeralAlignment.Proportional,我希望它改爲FontNumeralAlignment.Tabular。

背景:在Windows 7(see bug report on Microsoft Connect)上,WPF 4.0 OpenType支持被破壞,並且不可能在僅包含數字和標點符號的運行中更改數字對齊方式。如果我至少可以將應用程序的默認設置更改爲表格,則可以採用一種解決方法。

回答

1

我還沒有嘗試過它,但也許重寫默認的DependencyProperty元數據將是一個解決方案?

像這樣的東西應該工作:

public static class Overrides 
{ 
    static Overrides() 
    { 
     Typography.NumeralAlignmentProperty.OverrideMetadata(typeof(Typography), new System.Windows.PropertyMetadata(FontNumeralAlignment.Tabular)); 
    } 
}