gpt4 book ai didi

c# - 为什么我的 XAML 代码没有运行?

转载 作者:太空宇宙 更新时间:2023-11-03 21:39:27 26 4
gpt4 key购买 nike

我的 C# 代码有效,但 XAML 代码无效...我不知道我犯了什么错误。我是 XAML 的新手,我尝试学习它。当我删除这段代码时:

KeyDown = "HandleKeyDown"

Initialized = "MainWindow_Initilized" Background ="DimGray">

那么就没有错误了。

<Window x:Class="Tetris.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="570" Width="525">
KeyDown = "HandleKeyDown"
Initialized = "MainWindow_Initilized" Background ="DimGray">

<DockPanel LastChildFill="False">
<StackPanel DockPanel.Dock="Right" Width="127">
<Label Content="Label" Height="56" Name="Scores" FontSize="28" FontWeight="Bold" />
<Label Content="Label" Height="56" Name="Lines" FontSize="28" FontWeight="Bold"/>
</StackPanel>
<Grid Name="MainGrid" Height="500" Width="250">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
</Grid>
</DockPanel>
</Window>

最佳答案

在声明 KeyDown 属性之前,您有一个额外的 >

注意颜色突出显示停止

<Window x:Class="Tetris.MainWindow"  
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="570" Width="525">
KeyDown = "HandleKeyDown"
Initialized = "MainWindow_Initilized" Background ="DimGray">

我不认为你打算在那里。

关于c# - 为什么我的 XAML 代码没有运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20105292/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com