今天早上我尝试再次运行我的 C#/XAML 应用程序(此处指出了之前的问题:Why did my XAML suddenly crash?)。
这一次,我至少收到了一些具体的错误消息,即“成员“ShowGridLines”无法识别或无法访问”。和“Windows 应用程序项目不支持标签。”
这是完整的 XAML:
<Page
x:Class="TimeAndSpaceLines.View.SectionN"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TimeAndSpaceLines.View"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid MinHeight="600" ShowGridLines="True" Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="320"></ColumnDefinition>
<ColumnDefinition MaxWidth="800"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<Label MinWidth="40" Content="From"></Label>
<TextBox x:Name="textBoxFromDate" MinWidth="120">
</TextBox>
</StackPanel>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<Label MinWidth="40">at
</Label>
<TextBox x:Name="textBoxFromTime" MinWidth="120" Grid.Row="1">
</TextBox>
</StackPanel>
<StackPanel Grid.Row="2" Orientation="Horizontal">
<Label MinWidth="40">To
</Label>
<TextBox x:Name="textBoxToDate" MinWidth="120">
</TextBox>
</StackPanel>
<StackPanel Grid.Row="3" Orientation="Horizontal">
<Label MinWidth="40">at
</Label>
<TextBox x:Name="textBoxToTime" MinWidth="120" Grid.Row="1">
</TextBox>
</StackPanel>
<Button
x:Name="buttonFindLocForDateRange"
MaxWidth="200"
Grid.Row="4"
Content="Find Location for Date Range">
</Button>
<Label
x:Name="labelPerson1_Red"
Grid.Row="5"
Content="(Person1_Red)"
Foreground="Red">
</Label>
<Label
x:Name="labelPerson2_Orange"
Grid.Row="6"
Content="(Person2_Orange)"
Foreground="Orange">
</Label>
<Label
x:Name="labelPerson3_Yellow"
Grid.Row="7"
Content="(Person3_Yellow)"
Foreground="Yellow">
</Label>
<Label
x:Name="labelPerson4_Green"
Grid.Row="8"
Content="(Person4_Green)"
Foreground="Green">
</Label>
<Label
x:Name="labelPerson5_Blue"
Grid.Row="9"
Content="(Person5_Blue)"
Foreground="Blue">
</Label>
<Label
x:Name="labelPerson6_Indigo"
Grid.Row="10"
Content="(Person6_Indigo)"
Foreground="Indigo">
</Label>
<Label
x:Name="labelPerson7_Violet"
Grid.Row="11"
Content="(Person7_Violet)"
Foreground="Violet">
</Label>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<Image>
</Image>
<Label>Prev
</Label>
<Label x:Name="labelSectionN" Content="(Section N)">
</Label>
<Label>Next
</Label>
</StackPanel>
<!-- Add a Bing Map component: Grid.Column="1" Grid.Row="1" Grid.RowCount="11" -->
</Grid>
</Page>
注意:唯一的区别是 XAML 的初始和命名空间部分如下:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
...并且 Grid 属性中没有 Background="{StaticResource ApplicationPageBackgroundThemeBrush}",此 XAML 在 Kaxaml 中按其应有的方式显示(目前非常难看,但此时这是可以预料的)。
最佳答案
您编写了一些仅支持 WPF 应用程序而不支持 WinRT 的 XAML。
WinRT 不包含 Label 控件,并且 Grid 没有 ShowGridLines 属性,这就是您的代码无法正常工作的原因。
WPF 和 WinRT 是两种独立的技术 - 两者都恰好使用 XAML 来创建用户界面 - 但您不应期望用 WPF 编写的 XAML 也能在 WinRT 中工作,反之亦然。
关于wpf - 标签不是有效的 XAML 元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13163719/