Silverlight 4:尝试绑定样式和资源时出现 XamlParseException
我正在使用 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 主题...
提前致谢,
迈克
I am using Silverlight 4 and I am trying to integrate one of the themes from the Silverlight 4 toolkit from April.
My App.xaml reads as follows:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/System.Windows.Controls.Theming.ExpressionDark.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
When my main window reads
<Grid x:Name="LayoutRoot" Background="{Binding Source={StaticResource ThemeBackgroundBrush}}">
<TextBlock Text="Test" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="{Binding Source={StaticResource ThemeForegroundBrush}}" />
</Grid>
It works perfectly. However I would like to use resources so I went ahead and did the following
<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>
It fails :-(
I have tried to place the resource style in other places like the App.xaml etc.
Anyone know how I can use resources so I don't have to specify the foreground for each TextBlock?
PS - I am using the ExpressionDark theme...
Thanks in Advance,
Mike
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为您需要绑定源部分。
使用过以下方法并且效果很好。
我过去
I don't believe that you need the Binding Source part.
I have used the following
in the past and it works well.