【问题标题】:Silverlight 4: XamlParseException when trying to bind with styles and resourcesSilverlight 4:尝试与样式和资源绑定时出现 XamlParseException
【发布时间】:2011-03-18 15:52:43
【问题描述】:

我正在使用 Silverlight 4,我正在尝试从 4 月开始集成 Silverlight 4 工具包中的一个主题。

我的 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 主题...

提前致谢,

迈克

【问题讨论】:

    标签: silverlight themes resources styles xamlparseexception


    【解决方案1】:

    我认为您不需要 Binding Source 部分。

    我用过以下

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

    过去,它运作良好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-16
      • 2014-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-22
      相关资源
      最近更新 更多