2015-12-07 47 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

作品,谢谢:) –

相关问题