我正在尝试在Windows窗体应用程序的主窗口中添加一个新选项卡,但是当我尝试运行应用程序({1}}时,我当前遇到异常。例外情况给出了描述:
未处理的类型' System.Windows.Markup.XamlParseException'发生在PresentationFramework.dll
中附加信息:'在类型' RiviamAgent.MainWindow'上调用构造函数。匹配指定的绑定约束引发异常。'行号' 3'和行位置' 9'。
应用程序的XamlParseException was unhandled
是:
XML
自上次工作以来,我对此<Window x:Class="RiviamAgent.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="RIVIAM | CONNECTOR" Height="640" Width="640"
ResizeMode="NoResize">
<Grid>
<TabControl>
<TabItem Header="Application" >
<Menu IsMainMenu="True" Background="White">
<MenuItem Header="_View">
<MenuItem Header="_Connections">
<MenuItem x:Name="rivMenu" Header="_RIVIAM Cloud" Click="connectorInfo">
</MenuItem>
<Separator />
<MenuItem x:Name="tppMenu" Header="_TPP SystmOne" Click="connectorInfo">
</MenuItem>
<MenuItem x:Name="emisMenu" Header="_EMIS Web" Click="connectorInfo">
</MenuItem>
</MenuItem>
<MenuItem Header="_Diagnostics" Click="diagMode"/>
<MenuItem Header="_About" Click="About_Riviam"/>
</MenuItem>
<TabControl x:Name="tabControl" Height="100" Width="100">
<TabItem Header="TabItem">
<Grid Background="#FFE5E5E5"/>
</TabItem>
<TabItem Header="Riviam">
<Grid Background="#FFE5E5E5"/>
</TabItem>
<TabItem Header="Browser">
<Grid Background="#FFE5E5E5" />
</TabItem>
</TabControl>
</Menu>
</TabItem>
<TabItem Header="Browser"></TabItem>
</TabControl>
<Image x:Name="rivlogo" Height="128" Width="128" Margin="451,49,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Source="ic_launcher.png"/>
<Image x:Name="connectedFlag" Height="30" Width="30" Margin="479,193,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Source="cloud.png"/>
<Image x:Name="disconnectedFlag" Height="30" Width="30" Margin="479,193,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Source="cloud_dark.png"/>
<TextBlock x:Name="unsentMsgs" Height="30" Width="30" Margin="479,193,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Text="!"/>
<Image x:Name="tppFlag" Source="tppswoosh.png" Margin="529,193,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width ="60"/>
<Image x:Name="emisFlag" Source="emiswoosh.png" Margin="529,193,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width ="60"/>
<TextBlock x:Name="blah1" HorizontalAlignment="Left" Margin="41,52,0,0" TextWrapping="Wrap" Text="Select service to refer to:" VerticalAlignment="Top"/>
<TextBlock x:Name="blah2" HorizontalAlignment="Left" Margin="41,89,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="56" Width="136"><Run Text="Select referral document:
(or drag it to the logo)"/></TextBlock>
<TextBlock x:Name="blahfoot" HorizontalAlignment="Left" Margin="319,10,0,0" TextWrapping="Wrap" Text="RIVIAM - Secure cloud for Health and Social Care" VerticalAlignment="Top" Height="24" Width="260"/>
<ComboBox x:Name="serviceList" Text="pls select" HorizontalAlignment="Left" Margin="182,49,0,0" VerticalAlignment="Top" Width="218" ></ComboBox>
<TextBox x:Name="fileName" Text=" " MaxLines="1" IsReadOnly="True" Margin="182,90,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Height="23" Width="161"/>
<Button x:Name="fileBtn" Content="Browse" HorizontalAlignment="Left" Margin="348,90,0,0" VerticalAlignment="Top" Width="52" Click="fileUpload" Height="23"/>
<Button x:Name="referBtn" Content="Send Referral and Patient Record" HorizontalAlignment="Left" Margin="182,150,0,0" VerticalAlignment="Top" Width="218" Click="referThis" Height="23"/>
<TextBlock x:Name="blahfoot_Copy" HorizontalAlignment="Left" Margin="39,198,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="49" Width="361"><Run FontWeight="Bold" Text="Notice"/><Run Text=": "/><Run Text="You must ensure that the patient has agreed to their data being shared "/><Run Text="with the provider. Please contact the RIVIAM help desk on 01225 945 020 if you are unsure."/></TextBlock>
<!-- end of normal view -->
<ScrollViewer x:Name="scroller" HorizontalAlignment="Left" VerticalScrollBarVisibility="Auto" Margin="39,329,0,0" VerticalAlignment="Top" Height="244" Width="327">
<TextBox x:Name="infoPane" TextWrapping="Wrap" Text="nothing" IsReadOnly="True"/>
</ScrollViewer>
<Button x:Name="f1Btn" Content="view Logs" HorizontalAlignment="Left" Margin="408,361,0,0" VerticalAlignment="Top" Width="121" Click="testFunction1"/>
<Button x:Name="f2Btn" Content="delete logs" HorizontalAlignment="Left" Margin="408,393,0,0" VerticalAlignment="Top" Width="121" Click="testFunction2"/>
<Button x:Name="f3Btn" Content="test function 3" HorizontalAlignment="Left" Margin="408,425,0,0" VerticalAlignment="Top" Width="121" Click="testFunction3"/>
<Button x:Name="cntxtBtn" Content="context" HorizontalAlignment="Left" Margin="408,553,0,0" VerticalAlignment="Top" Width="121" Click="Context_Click"/>
</Grid>
</Window>
所做的唯一编辑是添加标记:
XML
在&#39;预览&#39;在Visual Studio中显示在XAML文件中写入的XML的面板,我可以看到我所做的更改是正确显示的,即窗口显示两个选项卡 - &#39;应用程序&#39; &安培; &#39;浏览器&#39;但由于某些原因,我在尝试运行应用程序时收到<TabControl>
<TabItem Header="Application" >
...
</TabItem>
<TabItem Header="Browser"></TabItem>
</TabControl>
。
我在SO上发现的大多数相关问题似乎都表明我需要在我的C#中为我的构造函数添加一个XamlParseException
块 - 我已经尝试过了,但它没有做到差异,并且鉴于自我的申请上次工作以来我唯一改变的是try-catch
文件,我本以为这个问题与XML有关 - 任何人都有任何建议吗?
修改
点击了查看详细信息&#39;在异常窗口中,它所抱怨的行似乎是我.xaml
类的声明:
Browser.cs
错误说:
在类型&#39; Agent.MainWindow&#39;上调用构造函数。匹配指定的绑定约束引发异常。&#39;行号&#39; 3&#39;和行位置&#39; 9&#39;。&#34;}
这是上面引用的partial class Browser{
行...
修改
进一步研究了一下,似乎在调用partial class Browser{
时抛出了异常...在整个解决方案中对MainWindow
的唯一调用是XAML的第一行文件:
MainWindow
我如何处理这样的XML异常?