当我从应用程序中的另一个窗口显示此窗口时出现以下错误:
发生XamlParseException'设置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四核
答案 0 :(得分:10)
尝试从Solution Explorer重建完整的解决方案。
答案 1 :(得分:4)
由于外部异常提到connectionid
,无效的强制转换必须在窗口附带的自动生成的代码文件中完成,并且可以在项目的obj
文件夹中找到。它应该被称为Window1.g.cs
。
查看Connect
方法,#line 4 ...
应该有一个案例,它会尝试附加Window.Loaded
事件,也许你可以看到为什么它会尝试投射它的方式
答案 2 :(得分:2)
我收到类似标题的错误,因为项目配置为在AnyCPU中构建,但依赖程序集设置为x86。将项目更改为x86解决了此问题。
答案 3 :(得分:0)
很可能是由于某些缺失的ddl。检查内部异常,你将对丢失的dll有一个线索。