スタイルのブラシをStaticResourceとして使用すると、実行時にSolidColorBrush(App.xamlで定義)を解決できない状況があります。
設計時に(Visual Studio 2010を使用して)ブラシが見つかりました。ブラシの色を変更すると、スタイルのあるUIElementが新しい色で更新されます。
実行時にXAMLParseExceptionが発生し、リソース「color」が見つかりません。
これは正常な動作ですか?StaticResourceの解決は、UIElementsからApplicationリソースまでであり、Applicationリソースは、アプリケーションのUIElementsのデフォルト値(色、フォントなど)を定義するのに適した場所であると思いました。
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>
<SolidColorBrush Color="Green" x:Key="color"/>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Styles.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="Border">
<Setter Property="BorderBrush" Value="{StaticResource color}" />
<Setter Property="BorderThickness" Value="1" />
</Style>
Main.xaml
<UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<Border Height="100" HorizontalAlignment="Left" Margin="130,146,0,0" Name="border1" VerticalAlignment="Top" Width="200" />
</Grid>