C# 启动窗口时发生xamlParseException

C# 启动窗口时发生xamlParseException,c#,wpf,xaml,xamlparseexception,C#,Wpf,Xaml,Xamlparseexception,当我从应用程序中的另一个窗口显示此窗口时,出现以下错误: 发生XamlParseException“Set-connectionId引发异常。” 行号“4”和行位置“25” 内部例外情况如下: {“无法强制转换'System.Windows.Controls.TabControl'类型的对象” 键入“WpfApplication1.Window1”。“} 我的xaml代码如下: <Window x:Class="WpfApplication1.Window1" xmlns="ht

当我从应用程序中的另一个窗口显示此窗口时,出现以下错误:

发生XamlParseException“Set-connectionId引发异常。” 行号“4”和行位置“25”

内部例外情况如下:

{“无法强制转换'System.Windows.Controls.TabControl'类型的对象” 键入“WpfApplication1.Window1”。“}

我的xaml代码如下:

 <Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="482" Width="603" Loaded="Window_Loaded">
<Grid>
    <TabControl Height="402" HorizontalAlignment="Right" Margin="0,0,12,0" Name="tabControl1" VerticalAlignment="Top" Width="569" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}">
        <TabItem Header="tabItem1" Name="tabItem1">
            <Grid></Grid>
        </TabItem>
        <TabItem Header="tabItem2" Name="tabItem2">
            <Grid Height="374" Width="563">
                <ListView Height="317" HorizontalAlignment="Left" Margin="6,10,0,0" Name="listView1" VerticalAlignment="Top" Width="550">
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Header="IP" DisplayMemberBinding="{Binding CustomerIP}"/>
                            <GridViewColumn Header="Host Name" DisplayMemberBinding="{Binding HostName}"/>
                            <GridViewColumn Header="MAC" DisplayMemberBinding="{Binding MAC}"/>
                            <GridViewColumn Header="Avg. Ping Time" DisplayMemberBinding="{Binding time}"/>
                        </GridView>
                    </ListView.View>
                </ListView>
            </Grid>
        </TabItem>
        <TabItem Header="tabItem3" Name="tabItem3">
            <Grid Height="307" />
        </TabItem>
    </TabControl>
    <Button Content="Cancel" Height="23" HorizontalAlignment="Left" Margin="330,408,0,0" Name="button1" VerticalAlignment="Top" Width="75" />
    <Button Content="Next" Height="23" HorizontalAlignment="Right" Margin="0,408,12,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" />
    <Button Content="Back" Height="23" HorizontalAlignment="Left" Margin="411,408,0,0" Name="button3" VerticalAlignment="Top" Width="75" IsEnabled="False" />
    <Rectangle Height="0" HorizontalAlignment="Left" Margin="13,40,0,0" Name="rectangle2" Stroke="Black" VerticalAlignment="Top" Width="453" />
    <ProgressBar Height="23" HorizontalAlignment="Left" Margin="5,408,0,0" Name="progressBar1" VerticalAlignment="Top" Width="319" Visibility="Hidden" />
    <Button Content="Remove" Height="23" HorizontalAlignment="Left" Margin="486,363,0,0" Name="button4" VerticalAlignment="Top" Width="75" IsEnabled="False" />
    <TextBox Height="23" HorizontalAlignment="Left" Margin="15,363,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" />
    <TextBox Height="23" HorizontalAlignment="Left" Margin="162,363,0,0" Name="textBox2" VerticalAlignment="Top" Width="120" />
    <Label Content="To" Height="28" HorizontalAlignment="Right" Margin="0,360,421,0" Name="label1" VerticalAlignment="Top" />
    <Button Content="Search" Height="23" HorizontalAlignment="Left" Margin="288,363,0,0" Name="button5" VerticalAlignment="Top" Width="75" Click="button5_Click" />
</Grid>

如果你需要我的C#代码来解决这个问题,我可以通过电子邮件发送给你,但将该代码发布到网上是违反公司政策的(我喜欢我的工作……我不想被解雇)

请记住,我通常是用VB.net开发的,而C#.net对我来说是非常新的,所以如果你能为初学者详细解释一下,我将不胜感激


c#net vs2010 Windows Vista x64
英特尔酷睿2 Quad

由于外部异常提到了
连接ID
,因此必须在自动生成的代码文件中执行无效转换,该文件随窗口一起出现,并位于项目的
obj
文件夹中。它应该被称为
Window1.g.cs


查看
Connect
方法,在
第4行…
中应该有一个案例,它试图附加
窗口。已加载的
事件,也许您可以理解为什么它会尝试以这种方式强制转换。

尝试从解决方案资源管理器重新生成完整的解决方案。

我收到一个标题类似的错误,原因是项目配置为在任何CPU中生成,但依赖程序集设置为x86。将项目更改为x86解决了此问题。

可能是由于缺少ddl。检查内部异常,您将获得有关缺少dll的线索。

该代码的丑陋之处在于使用GUI设计器,使用
网格
而不创建行和列是毫无意义的…在VB中,您永远不必编写此类代码,因此请原谅这种丑陋。。。这是blogCode vs2010 autogen代码的混合体。我建议手动编码,否则迟早会导致无法读取和维护的结果。如果删除
Loaded=“Window\u Loaded”
,会发生什么情况?Luks对我来说就像是代码隐藏错误,而不是XAML解析器错误。在我看来,装了窗户的似乎是罪魁祸首。也刚刚被发现。为什么被否决?一次完整的重建为我解决了这个问题。事实上,右键单击项目并重建解决了它。