我是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>
我收到錯誤「成員‘背景’不能識別或無法訪問」,我不明白爲什麼。我想一個語法錯誤,但不能爲我的生活看到它是什麼。
'TextBlock'沒有背景屬性 – thumbmunkeys 2014-10-07 12:28:54
@thumbmunkeys上面鏈接到的MSDN頁面是否不適用於Windows 8 Metro應用程序? – 2014-10-07 12:32:44
顯然不是,請參閱我的回答 – thumbmunkeys 2014-10-07 12:36:15