0
我有我的代碼中的兩個錯誤:根級別的數據無效。 1號線,位置1. XML是無效
在根級別- 數據是無效的。第1行,位置1.
- 標記文件無效。指定一個擴展名爲.xaml的源標記文件。
爲什麼?
MainWindow.xaml:
<Window x:Class="TestWpfApplication.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Eight Ball Answer" Height="328" Width="412" >
<Grid Name="grid1">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="10,10,13,10" Name="txtQuestion" TextWrapping="Wrap" FontFamily="Verdana" FontSize="24" Grid.Row="0">[Place question here.]</TextBox>
<Button VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,0,0,20" Width="127" Height="23" Name="cmdAnswer" Click="cmdAnswer_Click" Grid.Row="1">Ask the Eight Ball</Button>
<TextBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="10,10,13,10" Name="txtAnswer" TextWrapping="Wrap" IsReadOnly="True" FontFamily="Verdana" FontSize="24" Foreground="Green" Grid.Row="2">[Answer will appear here.]</TextBox>
<Grid.Background>
<LinearGradientBrush>
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0.00" Color="Red" />
<GradientStop Offset="0.50" Color="Indigo" />
<GradientStop Offset="1.00" Color="Violet" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Grid.Background>
</Grid>
</Window>
MainWindow.xaml.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace TestWpfApplication
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void cmdAnswer_Click(object sender, RoutedEventArgs e)
{
this.Cursor = Cursors.Wait;
txtAnswer.Text = "AAA";
this.Cursor = null;
}
}
}
更新1:
- 本頁面被複制粘貼&方法創建,而不是由設計師。
- MainWindow.xaml將PropertyAction屬性設置爲Page。
是否有幫助?
我拷貝了這個xaml和cs代碼,它的編譯和工作正常。重新啓動Visual Studio可能是解決方案 – bakala12
如果重新啓動不起作用,您可以創建一個新項目並複製您的內容。 – nidhoeggr09
它不適用於我的VS:2012Professional,2015在線。任何其他需要分析的文件? –