2010-07-20 70 views
0

我正在使用Silverlight 4,並試圖從4月份的Silverlight 4工具包中集成其中一個主題。Silverlight 4:嘗試綁定樣式和資源時出現XamlParseException

我的App.xaml如下:

<Application.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="Themes/System.Windows.Controls.Theming.ExpressionDark.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Application.Resources> 

當我的主窗口中讀取

<Grid x:Name="LayoutRoot" Background="{Binding Source={StaticResource ThemeBackgroundBrush}}"> 
    <TextBlock Text="Test" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="{Binding Source={StaticResource ThemeForegroundBrush}}" /> 
</Grid> 

它完美。不過,我想用資源,所以我說幹就幹,做了以下

<Grid x:Name="LayoutRoot" Background="{Binding Source={StaticResource ThemeBackgroundBrush}}"> 
    <Grid.Resources> 
     <Style TargetType="TextBlock"> 
      <Setter Property="Foreground" Value="{Binding Source={StaticResource ThemeForegroundBrush}}" /> 
     </Style> 
    </Grid.Resources> 
    <TextBlock Text="Test" HorizontalAlignment="Center" VerticalAlignment="Center" /> 
</Grid> 

它:-(失敗

我試圖把資源風格在其他地方一樣的App.xaml等

任何人都知道我該如何使用資源,這樣我就不必指定前景爲每個TextBlock的

PS? - 我使用ExpressionDark主題...

由於事先

邁克

回答

3

我不認爲你需要的綁定源一部分。

我已經使用了以下

<Setter Property="Foreground" Value="{StaticResource ThemeForegroundBrush}" /> 
過去

,而且運作良好。

+0

謝謝Justing - 完美的作品! – mkamioner 2010-07-20 20:31:36