[英]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.