[英]Why is my XAML Code not running?
我的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">
我不认为你打算那样做。
因为您关闭了Window标记两次:
Title="MainWindow" Height="570" Width="525">
KeyDown = "HandleKeyDown"
Initialized = "MainWindow_Initilized" Background ="DimGray">
您在Width="525"
之后关闭它,并在Background ="DimGray"
之后再次关闭它。 在Width="525"
之后删除一个,如果你在Window XAML的最底部有</Window>
,它应该没问题。
此外,如果您尝试使用KeyDown
来实现键盘快捷键,您应该做这样的事情:
<Window.InputBindings>
<KeyBinding Gesture="Ctrl+O" Command="{commands:ApplicationCommand}" CommandParameter="OpenFile"/>
</Window.InputBindings>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.