您的示例代码在App.xaml合并资源字典源中使用了双等号,用于Palette.Blue.xaml。我猜这只是您在此处发布示例时的笔误,而不是您真正遇到的问题。
在XAML中直接链接所有资源可能有些棘手。最简单的方法是从Blend的资源面板中完成。我创建了一个名为您示例的Silverlight应用程序,并在Blend中打开该项目,然后非常快速地将它们链接在一起。
App.xaml
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="SilverlightApplication1.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Theme.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Theme.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Palette.Blue.xaml"/>
<ResourceDictionary Source="Template.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Template.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="TextBox">
<Setter Property="Margin" Value="10" />
<Setter Property="Width" Value="250" />
</Style>
<Style x:Key="ReadOnlyTextBoxStyle" TargetType="TextBox">
<Setter Property="IsReadOnly" Value="True" />
<Setter Property="Foreground" Value="Black" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Margin" Value="10" />
<Setter Property="Width" Value="250" />
</Style>
</ResourceDictionary>
Palette.Blue.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="BlueSolidColorBrush" Color="SkyBlue" />
</ResourceDictionary>
MainPage.xaml
<UserControl x:Class="SilverlightApplication1.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel x:Name="LayoutRoot" Background="Honeydew">
<TextBox Text="Read Only Textbox"
Style="{StaticResource ReadOnlyTextBoxStyle}" />
<TextBox Text="Blue Textbox"
Background="{StaticResource BlueSolidColorBrush}" />
<TextBox Text="Read Only, Blue Textbox"
Style="{StaticResource ReadOnlyTextBoxStyle}"
Background="{StaticResource BlueSolidColorBrush}" />
</StackPanel>
</UserControl>
当然,如果您从不同的程序集中链接资源,那么它看起来会有所不同。事实上,在这种情况下,我建议您在代码后台合并您的字典。