我的MainPage.xaml中有这个XAML代码,它创建行和列定义以及一个TextBlock
<Page
x:Class="App2.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App2"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid x:Name="layoutGrid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="140"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="TEST"
Grid.Row="1"
Grid.Column="1"
Height="23"
HorizontalAlignment="Right"
Margin="0,45,70,0"
x:Name="Test TextBlock"/>
</Grid>
</Page>如果存在TextBlock,则MainPage.xaml.cs中会出现错误。

我不知道这段代码有什么问题。如果我在TextBlock页面上注释掉了.xaml,错误就会消失。这里是一个完整的代码,屏幕截图显示了我遇到的问题。
发布于 2015-04-16 19:44:16
x:Name="Test TextBlock"x:Name定义了该对象的变量名。Test TextBlock不是有效的标识符。使用TestTextBlock。另外,您可以浏览一下InitializeComponent,或者阅读您的错误消息。XAML文件中的错误字面上是这样的(看看蓝色的squigglies):
‘'Test’不是属性'Name‘的有效值
https://stackoverflow.com/questions/29684517
复制相似问题