2014-10-07 52 views
1

我是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> 

我收到錯誤「成員‘背景’不能識別或無法訪問」,我不明白爲什麼。我想一個語法錯誤,但不能爲我的生活看到它是什麼。

+0

'TextBlock'沒有背景屬性 – thumbmunkeys 2014-10-07 12:28:54

+0

@thumbmunkeys上面鏈接到的MSDN頁面是否不適用於Windows 8 Metro應用程序? – 2014-10-07 12:32:44

+0

顯然不是,請參閱我的回答 – thumbmunkeys 2014-10-07 12:36:15

回答

1

This is the documentation它適用於您的類型的應用程序。

在這種情況下TextBlock沒有Background屬性。

+0

謝謝。我一直在MSDN中苦苦掙扎。 – 2014-10-07 12:38:11

+1

不客氣!我知道你的痛苦,有太多的版本...... – thumbmunkeys 2014-10-07 12:44:19