[英]Why is my XAML Code not running?
my C# Code works, but the XAML Code isn't working... I don't know what mistake I make. 我的C#代码有效,但XAML代码无效......我不知道我犯了什么错误。 I'm a newbie on XAML and I try to learn it.
我是XAML的新手,我试着学习它。 When I delete this code:
当我删除此代码时:
KeyDown = "HandleKeyDown"
KeyDown =“HandleKeyDown”
Initialized = "MainWindow_Initilized" Background ="DimGray">
Initialized =“MainWindow_Initilized”Background =“DimGray”>
then there is no error. 那就没有错误。
<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>
you have an extra >
there right before you declare your KeyDown
attribute. 在声明
KeyDown
属性之前,你有一个额外的>
。
Take note of there the color highlight stops 请注意那里的颜色突出显示停止
<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">
I don't think you intend for that to be there. 我不认为你打算那样做。
Because you closed the Window tag twice: 因为您关闭了Window标记两次:
Title="MainWindow" Height="570" Width="525">
KeyDown = "HandleKeyDown"
Initialized = "MainWindow_Initilized" Background ="DimGray">
You closed it after Width="525"
and again after Background ="DimGray"
. 您在
Width="525"
之后关闭它,并在Background ="DimGray"
之后再次关闭它。 Remove the one after Width="525"
and it should be fine provided that you have </Window>
at the very bottom of your Window XAML. 在
Width="525"
之后删除一个,如果你在Window XAML的最底部有</Window>
,它应该没问题。
Also, if you are trying to use KeyDown
to implement keyboard shortcuts, you should be doing something like this instead: 此外,如果您尝试使用
KeyDown
来实现键盘快捷键,您应该做这样的事情:
<Window.InputBindings>
<KeyBinding Gesture="Ctrl+O" Command="{commands:ApplicationCommand}" CommandParameter="OpenFile"/>
</Window.InputBindings>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.