【发布时间】:2014-10-07 12:27:02
【问题描述】:
我正在尝试为 TextBlock 定义样式。在 MSDN 上找到 this 示例,说明如何设置样式(在第一个代码块中)。
我的 XAML 是:
<Page
x:Name="pageRoot"
x:Class="MyPrototype.MainPage"
DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyPrototype"
xmlns:common="using:MyPrototype.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Page.Resources>
<!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
<x:String x:Key="AppName">MyPrototype</x:String>
<x:String x:Key="AppTitle">MyPrototype</x:String>
<Style TargetType="TextBlock" x:Key="TitleTextBlockStyle">
<Setter Property="Background" Value="Red"/>
<Setter Property="FontFamily" Value="Trebuchet MS"/>
<Setter Property="Foreground" Value="White" />
<Setter Property="FontSize" Value="18"/>
</Style>
</Page.Resources>
<StackPanel Orientation="Horizontal" >
<TextBlock Style="{StaticResource TitleTextBlockStyle}" Text="My Prototype Main Page"/>
</StackPanel>
我收到错误:
成员“背景”无法识别或无法访问
我不明白为什么。我猜是语法错误,但看不到是什么。
【问题讨论】:
标签: xaml windows-runtime textblock