2015-12-07 112 views

回答

1

您可以直接在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是不是在設計時,該代碼刪除無用的風格。

+0

作品,謝謝:) –

相關問題