文章目录
- 问题现象
- 解决方案
问题现象
一个以前使用.NET Framwork 3.0框架开发的项目,在框架升级到.NET Framwork 4.7.2后,
如下代码:
#pragma checksum "..\..\XpsViewer.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "4141923E04B8F37EBAC5AA6FD24010A2242046815AD9C4F159F31F5E02A435EE"
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms.Integration;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using System.Windows.Media.TextFormatting;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Shell;
namespace xpsview {
/// <summary>
/// XpsViewer
/// </summary>
public partial class XpsViewer : System.Windows.Controls.UserControl, System.Windows.Markup.IComponentConnector, System.Windows.Markup.IStyleConnector {
#line 114 "..\..\XpsViewer.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.DocumentViewer documentViewer;
#line default
#line hidden
private bool _contentLoaded;
/// <summary>
/// InitializeComponent
/// </summary>
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
public void InitializeComponent() {
if (_contentLoaded) {
return;
}
_contentLoaded = true;
System.Uri resourceLocater = new System.Uri("/xpsview;component/xpsviewer.xaml", System.UriKind.Relative);
#line 1 "..\..\XpsViewer.xaml"
System.Windows.Application.LoadComponent(this, resourceLocater);
#line default
#line hidden
}
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
switch (connectionId)
{
case 1:
#line 4 "..\..\XpsViewer.xaml"
((xpsview.XpsViewer)(target)).Loaded += new System.Windows.RoutedEventHandler(this.UserControl_Loaded);
#line default
#line hidden
#line 4 "..\..\XpsViewer.xaml"
((xpsview.XpsViewer)(target)).KeyUp += new System.Windows.Input.KeyEventHandler(this.UserControl_KeyUp);
#line default
#line hidden
#line 4 "..\..\XpsViewer.xaml"
((xpsview.XpsViewer)(target)).KeyDown += new System.Windows.Input.KeyEventHandler(this.UserControl_KeyDown);
#line default
#line hidden
return;
case 26:
this.documentViewer = ((System.Windows.Controls.DocumentViewer)(target));
#line 114 "..\..\XpsViewer.xaml"
this.documentViewer.AddHandler(System.Windows.Documents.Hyperlink.RequestNavigateEvent, new System.Windows.Navigation.RequestNavigateEventHandler(this.documentViewer_RequestNavigate));
#line default
#line hidden
#line 114 "..\..\XpsViewer.xaml"
this.documentViewer.TargetUpdated += new System.EventHandler<System.Windows.Data.DataTransferEventArgs>(this.documentViewer_TargetUpdated);
#line default
#line hidden
return;
case 27:
#line 117 "..\..\XpsViewer.xaml"
((System.Windows.Input.CommandBinding)(target)).CanExecute += new System.Windows.Input.CanExecuteRoutedEventHandler(this.CommandBinding_CanExecutePrint);
#line default
#line hidden
return;
case 28:
#line 118 "..\..\XpsViewer.xaml"
((System.Windows.Input.CommandBinding)(target)).CanExecute += new System.Windows.Input.CanExecuteRoutedEventHandler(this.CommandBinding_CanExecuteCopy);
#line default
#line hidden
return;
}
this._contentLoaded = true;
}
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
void System.Windows.Markup.IStyleConnector.Connect(int connectionId, object target) {
switch (connectionId)
{
case 2:
#line 28 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.btnQuit_Click);
#line default
#line hidden
#line 28 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Button)(target)).Loaded += new System.Windows.RoutedEventHandler(this.btnQuit_Loaded);
#line default
#line hidden
break;
case 3:
#line 29 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Image)(target)).Loaded += new System.Windows.RoutedEventHandler(this.changeLanguage);
#line default
#line hidden
break;
case 4:
#line 31 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Label)(target)).Loaded += new System.Windows.RoutedEventHandler(this.btnQuit_Loaded);
#line default
#line hidden
break;
case 5:
#line 32 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Separator)(target)).Loaded += new System.Windows.RoutedEventHandler(this.btnQuit_Loaded);
#line default
#line hidden
break;
case 6:
#line 34 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.btnPrint_Click);
#line default
#line hidden
#line 34 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Button)(target)).Loaded += new System.Windows.RoutedEventHandler(this.PrintSupport_Loaded);
#line default
#line hidden
break;
case 7:
#line 35 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Image)(target)).Loaded += new System.Windows.RoutedEventHandler(this.changeLanguage);
#line default
#line hidden
break;
case 8:
#line 37 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Separator)(target)).Loaded += new System.Windows.RoutedEventHandler(this.PrintSupport_Loaded);
#line default
#line hidden
break;
case 9:
#line 41 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Image)(target)).Loaded += new System.Windows.RoutedEventHandler(this.changeLanguage);
#line default
#line hidden
break;
case 10:
#line 45 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Image)(target)).Loaded += new System.Windows.RoutedEventHandler(this.changeLanguage);
#line default
#line hidden
break;
case 11:
#line 53 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Image)(target)).Loaded += new System.Windows.RoutedEventHandler(this.changeLanguage);
#line default
#line hidden
break;
case 12:
#line 57 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Image)(target)).Loaded += new System.Windows.RoutedEventHandler(this.changeLanguage);
#line default
#line hidden
break;
case 13:
#line 61 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Image)(target)).Loaded += new System.Windows.RoutedEventHandler(this.changeLanguage);
#line default
#line hidden
break;
case 14:
#line 65 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Image)(target)).Loaded += new System.Windows.RoutedEventHandler(this.changeLanguage);
#line default
#line hidden
break;
case 15:
#line 68 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Separator)(target)).Loaded += new System.Windows.RoutedEventHandler(this.seperatorNextPrev_Loaded);
#line default
#line hidden
break;
case 16:
#line 69 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Label)(target)).Loaded += new System.Windows.RoutedEventHandler(this.seperatorNextPrev_Loaded);
#line default
#line hidden
break;
case 17:
#line 70 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.btnPrev_Click);
#line default
#line hidden
#line 70 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Button)(target)).Loaded += new System.Windows.RoutedEventHandler(this.seperatorNextPrev_Loaded);
#line default
#line hidden
break;
case 18:
#line 71 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Image)(target)).Loaded += new System.Windows.RoutedEventHandler(this.changeLanguage);
#line default
#line hidden
break;
case 19:
#line 73 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.btnNext_Click);
#line default
#line hidden
#line 73 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Button)(target)).Loaded += new System.Windows.RoutedEventHandler(this.seperatorNextPrev_Loaded);
#line default
#line hidden
break;
case 20:
#line 74 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Image)(target)).Loaded += new System.Windows.RoutedEventHandler(this.changeLanguage);
#line default
#line hidden
break;
case 21:
#line 77 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Label)(target)).Loaded += new System.Windows.RoutedEventHandler(this.seperatorNextPrev_Loaded);
#line default
#line hidden
break;
case 22:
#line 80 "..\..\XpsViewer.xaml"
((System.Windows.Controls.TextBox)(target)).Loaded += new System.Windows.RoutedEventHandler(this.editPage_Loaded);
#line default
#line hidden
#line 80 "..\..\XpsViewer.xaml"
((System.Windows.Controls.TextBox)(target)).KeyUp += new System.Windows.Input.KeyEventHandler(this.editPage_KeyUp);
#line default
#line hidden
#line 80 "..\..\XpsViewer.xaml"
((System.Windows.Controls.TextBox)(target)).PreviewTextInput += new System.Windows.Input.TextCompositionEventHandler(this.editPage_PreviewTextInput);
#line default
#line hidden
break;
case 23:
#line 88 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.btnToggle_Click);
#line default
#line hidden
break;
case 24:
#line 89 "..\..\XpsViewer.xaml"
((System.Windows.Controls.Image)(target)).Loaded += new System.Windows.RoutedEventHandler(this.changeLanguage);
#line default
#line hidden
break;
case 25:
#line 102 "..\..\XpsViewer.xaml"
((System.Windows.Controls.ContentControl)(target)).Loaded += new System.Windows.RoutedEventHandler(this.PART_FindToolBarHost_Loaded);
#line default
#line hidden
break;
}
}
}
}
报如下错误:
1>xxx\Viewer.g.cs(41,97,41,116): error CS1069: 未能在命名空间“System.Windows.Markup”中找到类型名“IComponentConnector”。此类型已转发到程序集“System.Xaml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”。请考虑添加对该程序集的引用。
1>xxx\XpsViewer.g.cs(78,36,78,55): error CS1069: 未能在命名空间“System.Windows.Markup”中找到类型名“IComponentConnector”。此类型已转发到程序集“System.Xaml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”。请考虑添加对该程序集的引用。
1>xxx\XpsViewer.g.cs(78,14,78,55): error CS0538: '显式接口声明中的“IComponentConnector”不是接口
解决方案
根据错误提示,其实就是需要添加System.Xaml的引用。
添加方法如下:
在项目引用处右键——添加引用——程序集——勾选上“System.Xaml”
如图: