【问题标题】:The member "Background" is not recognised or is not accessible成员“背景”无法识别或无法访问
【发布时间】: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


    【解决方案1】:

    This is the documentation 适用于您的应用类型。

    在这种情况下,TextBlock 没有 Background 属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-07
      • 2012-11-09
      • 2015-02-13
      • 1970-01-01
      • 1970-01-01
      • 2015-11-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多