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 –