Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight 应用程序的隐式样式_Silverlight_Xaml - Fatal编程技术网

Silverlight 应用程序的隐式样式

Silverlight 应用程序的隐式样式,silverlight,xaml,Silverlight,Xaml,隐式样式在App.xaml中不起作用,但正在使用本地页面资源。如何为控件创建全局样式 <navigation:Page.Resources> <Style TargetType="Button"> <Setter Property="Background" Value="Red" /> <Setter Property="Foreground" Value="Navy" /> </Style> </navigation

隐式样式在App.xaml中不起作用,但正在使用本地页面资源。如何为控件创建全局样式

<navigation:Page.Resources>
 <Style TargetType="Button">
  <Setter Property="Background" Value="Red" />
  <Setter Property="Foreground" Value="Navy" />
 </Style>
</navigation:Page.Resources>

在App.xaml中

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="StilDict.xaml" />
        </ResourceDictionary.MergedDictionaries>
 </ResourceDictionary>


希望有帮助

这适用于按钮

<Style TargetType="ButtonBase">
 <Setter Property="Background" Value="Red" />
 <Setter Property="Foreground" Value="Navy" />
</Style>


Ohh你说得对。只需删除x:Key=“ButtonStyleNavyOnRed”部分。然后我测试了它。谢谢你的警告。是的,我正在使用app.xaml中的合并词典。从我读到的内容来看,当您不在样式上指定键时,它将在声明中隐式地将样式设置为TargetType的所有控件。我正试图让它在全球范围内工作,而不仅仅是在页面资源中,正如我上面所示。我不知道要改变什么来解决这个问题。谢谢你的建议。我想你没有看到我的便笺和链接,你是对的。删除键attrb,它可以工作,不需要设置样式。不,我看到了,不管是什么原因,我的设计师不稳定-我的所有样式都显示为未找到->重建并重新打开,现在一切都好了。就像是当时的词典合并有多么的缺失——尽管它就在那里。谢谢,它只适用于buttonbase对象,还是适用于buttons的alo?它应该是从buttonbase派生的所有对象。奇怪的是,TargetType=ButtonBase一开始工作,然后它就停止工作了,我切换到TargetType=Button,它又工作了???按照我帖子的链接结尾,MS说“如果你隐式设置样式,样式只应用于与TargetType完全匹配的类型,而不应用于从TargetType值派生的元素”
 <UserControl>
    <Button Style={StaticResource ButtonStyleNavyOnRed} Content="Yahoo! :)"/>
 </UserControl>
<Style TargetType="ButtonBase">
 <Setter Property="Background" Value="Red" />
 <Setter Property="Foreground" Value="Navy" />
</Style>