我是XAML的新手,并尝试为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>
我收到错误“会员”背景“无法识别或无法访问”,我看不出原因。我猜一个语法错误,但不能为我的生活看到它是什么。