Windows Phone 8 应用程序不包含 InitializeComponent 的定义 [英] Windows Phone 8 app does not contain a definition for InitializeComponent

查看:14
本文介绍了Windows Phone 8 应用程序不包含 InitializeComponent 的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚下载了 Visual Studio 的 14 CTP 版本,并为 Windows Phone 创建了一个空白应用程序.我试图打开 MainPage.xaml 并且设计器显示以下错误:

I have just downloaded the 14 CTP version of Visual Studio and created a blank app for Windows Phone. I tried to open the MainPage.xaml and the designer shows up the following errors:

对于那些看不到图像的人:

and for those who can't see the image:

System.Exception
Package failed updates, dependency or conflict validation.

Windows cannot install package App.a5cd6ef3c.a895b.a4508.a96fd.af1634c30bb13 because this package depends on another package that could not be found. This package requires minimum version 0.0.0.0 of framework Microsoft.VCLibs.140.00.Debug published by any publisher to install. Provide the framework along with this package.
   at Microsoft.Expression.HostUtility.Platform.AppContainerProcessDomainFactory.CreateDesignerProcess(String applicationPath, String clientPort, Uri hostUri, IDictionary environmentVariables, Int32& processId, Object& processData)
   at Microsoft.Expression.DesignHost.Isolation.Primitives.ProcessDomainFactory.ProcessIsolationDomain..ctor(ProcessDomainFactory factory, IIsolationBoundary boundary, AppDomainSetup appDomainInfo, FrameworkName targetFramework, String identifier, String baseDirectory)
   at Microsoft.Expression.DesignHost.Isolation.Primitives.ProcessDomainFactory.CreateIsolationDomain(IIsolationBoundary boundary)
   at Microsoft.Expression.HostUtility.Platform.AppContainerProcessDomainFactory.CreateIsolationDomain(IIsolationBoundary boundary)
   at Microsoft.Expression.DesignHost.Isolation.Primitives.IsolationBoundary.Initialize()
   at Microsoft.Expression.DesignHost.Isolation.Primitives.IsolationBoundary.CreateInstance[T](Type type)
   at Microsoft.Expression.DesignHost.Isolation.IsolatedObjectFactory.Initialize()
   at Microsoft.VisualStudio.ExpressionHost.Services.VSIsolationService.CreateObjectFactory(IIsolationTarget isolationTarget, IObjectCatalog catalog)
   at Microsoft.Expression.DesignHost.Isolation.IsolationService.CreateLease(IIsolationTarget isolationTarget)
   at Microsoft.Expression.DesignHost.Isolation.IsolationService.CreateLease(IIsolationTarget isolationTarget)
   at Microsoft.Expression.DesignHost.Isolation.IsolationService.CreateLease(IIsolationTarget isolationTarget)
   at Microsoft.Expression.DesignHost.IsolatedDesignerService.CreateLease(IIsolationTarget isolationTarget, CancellationToken cancelToken, DesignerServiceEntry& entry)
   at Microsoft.Expression.DesignHost.IsolatedDesignerService.IsolatedDesignerView.CreateDesignerViewInfo(CancellationToken cancelToken)
   at Microsoft.Expression.DesignHost.Isolation.IsolatedTaskScheduler.InvokeWithCulture[T](CultureInfo culture, Func`2 func, CancellationToken cancelToken)
   at Microsoft.Expression.DesignHost.Isolation.IsolatedTaskScheduler.<>c__DisplayClass5`1.<StartTask>b__7()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()

我输入了 App1.xaml.csMainPage.xaml.cs 并且我看到了 AppMainPage 分别没有 InitializeComponent() 的定义.

I entered App1.xaml.cs and MainPage.xaml.cs and I've seen that App and MainPage, respectively, don't have a definition for InitializeComponent().

项目处于由 Visual Studio 创建的状态,我没有更改任何内容!

为什么会发生这种情况,我该如何解决?

Why is this happening and how can I solve it?

推荐答案

确保 XAML 上的类名与代码隐藏中的类名匹配.我在重构时遇到过几次这种情况.

Ensure the class name on your XAML matches the class name in your code-behind. I've run into this a few times while refactoring.

XAML 开始标记:

<UserControl
    x:Class="Namespace.Foo"
    ... />

背后的代码:

public sealed partial class Bar : UserControl
{
    public Bar()
    {
        // This will become the error specified (does not contain definition)
        this.InitializeComponent(); 
    }
    ...
}

所以 Namespace.Foo 在这里需要是 Namespace.Bar 来消除错误.如果使用 Page 而不是 UserControl,这应该具有相同的行为.

So Namespace.Foo would need to be Namespace.Bar here to get rid of the error. This should have the same behavior if using Page instead of UserControl.

这篇关于Windows Phone 8 应用程序不包含 InitializeComponent 的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆