窗口启动时出现 xamlParseException
当我从应用程序中的另一个窗口显示此窗口时,出现以下错误:
发生 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 四核
I get the following error when I show this window from another window in my application:
XamlParseException occurred 'Set connectionId threw an exception.'
Line number '4' and line position '25'.
With an inner exception of:
{"Unable to cast object of type 'System.Windows.Controls.TabControl'
to type 'WpfApplication1.Window1'."}
My xaml code is as follows:
<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>
If you need my C# code to figure out this problem I can Email it to you, but it is against company policy to put that code on the web (and I enjoy my job... I dont want to get fired)
Please keep in mind that I normaly develop in VB.net, and C#.net is very new to me, so if you could please detail your explanations for a beginner that would be appreciated.
c#.net
vs2010
Windows Vista x64
Intel Core 2 Quad
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试从解决方案资源管理器重建完整的解决方案。
Try Rebuilding the complete solution from Solution Explorer.
由于外部异常提到了
connectionid
,因此必须在窗口附带的自动生成的代码文件中完成无效转换,该文件位于项目的obj
文件夹中。它应该被称为Window1.g.cs
。查看
Connect
方法,应该有一个#line 4 ...
尝试附加Window.Loaded
事件的情况,也许你可以明白为什么它会尝试这样做。Since the outer exception mentions the
connectionid
the invalid cast has to be done in a automatically generated code file that accompanies the window and is found in theobj
folder of the project. It should be calledWindow1.g.cs
.Look at the
Connect
method, there should be a case with#line 4 ...
where it tries to attach theWindow.Loaded
event, maybe you can see why it tries to cast the way it does.我收到了一个类似标题的错误,这是因为该项目被配置为在 AnyCPU 中构建,但依赖程序集被设置为 x86。将项目更改为 x86 解决了此问题。
I received a similarly titled error and it was because the project was configured to build in AnyCPU, but a dependent assembly was set as x86. Changing the project to x86 resolved this issue.
这可能是由于缺少一些 ddl 造成的。检查内部异常,您将获得有关丢失的 dll 的线索。
It is likly due to some missing ddl. check the inner exception and you will have a clue about the missing dll.