2010-01-07 105 views
3
<Window.Resources> 
<Style TargetType="{x:Type Button}">  
    <Setter Property="FontFamily" Value="Times New Roman" /> 
    <Setter Property="FontSize" Value="30" />  
    <Setter Property="FontWeight" Value="Bold" />  
    <Setter Property="Background" Value="#FFCA5132" /> 
</Style> 
</Window.Resources> 

此上面的代码看起来像是将WPF样式应用于特定窗口中的所有按钮的正确选择。但我想将这种风格应用于我的程序中的所有按钮。 我想我需要在<Application.Resources></Application.Resources>中写下这段代码。但它不运行。我怎样才能做到这一点?如何将WPF样式应用于特定类型的所有元素?

+2

当你写这Application.Resources会发生什么。你有编译器错误吗?如果是这样,你能告诉我们错误是什么。 – Tarydon 2010-01-07 02:11:21

+0

那里,格式化你的代码。为了将来的参考,在每行或每行代码前放置四个空格,并且对于内嵌代码''this''用反引号(''asdasd'')包围它。现在,对于这个问题,当你把它放在Application.Resources中会发生什么? – 2010-01-07 02:11:39

回答

0

<Application.Resources>ResourceDictionary。您无法将其添加到ResourceDictionaryStyle之间,就像您在代码中所做的那样。放置StyleResourceDictionary里面,像这样:

<Application.Resources>  

<ResourceDictionary Source="/PresentationFramework.Aero 
         , Version=3.0.0.0,Culture=neutral 
         , PublicKeyToken=31bf3856ad364e35 
         , ProcessorArchitecture=MSIL;component/themes/aero.normalcolor.xaml">    
    <ResourceDictionary.MergedDictionaries> 
    <ResourceDictionary Source="Style\AppStyle.xaml"></ResourceDictionary> 
    </ResourceDictionary.MergedDictionaries> 

    <Style TargetType="{x:Type Button}"> 
     <Setter Property="FontFamily" Value="meiryo" /> 
     <Setter Property="FontSize" Value="12" /> 
    </Style> 
    </ResourceDictionary> 
</Application.Resources> 
+0

感谢您的咨询。但它仍然无法运行。 顺便说一句,我有另一种解决方案。 在AppStyle.xaml文件中,我为窗体窗体创建了一个样式,并将按钮样式放在那里。它运行正常! – huynq9 2010-01-07 04:23:21

相关问题