0
如何設置標準文字樣式(fontsize,fontfamily等),因此每個控件(標籤,文本框等)都將顯示其內容文本,並顯示新的字體在設計時?Visual Studio - WPF - 在設計時設置標準文字樣式
感謝您的幫助!
如何設置標準文字樣式(fontsize,fontfamily等),因此每個控件(標籤,文本框等)都將顯示其內容文本,並顯示新的字體在設計時?Visual Studio - WPF - 在設計時設置標準文字樣式
感謝您的幫助!
您可以直接在XAML設置你的窗口TextElement附加屬性,這樣的事情:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="300" Width="300"
TextElement.FontFamily="Bradley Hand ITC"
TextElement.FontSize="16">
// your XAML is here
</Window>
然後 - 爲了避免這種「默認文本樣式」用於運行時間太 - 你只需要在窗口的構造函數中添加以下代碼:
public MainWindow()
{
InitializeComponent();
if (!DesignerProperties.GetIsInDesignMode(this))
{
DependencyPropertyDescriptor dependencyPropertyDescriptor =
DependencyPropertyDescriptor.FromProperty(TextElement.FontFamilyProperty, GetType());
dependencyPropertyDescriptor.SetValue(this, DependencyProperty.UnsetValue);
dependencyPropertyDescriptor =
DependencyPropertyDescriptor.FromProperty(TextElement.FontSizeProperty, GetType());
dependencyPropertyDescriptor.SetValue(this, DependencyProperty.UnsetValue);
}
}
因此,如果您Window
是不是在設計時,該代碼刪除無用的風格。
作品,謝謝:) –
在這裏回答:http://stackoverflow.com/questions/14908148/apply-an-application-level-style-to-all-textboxes –