Windows Phone 8 应用程序不包含 InitializeComponent 的定义

27 浏览
0 Comments

Windows Phone 8 应用程序不包含 InitializeComponent 的定义

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

enter image description here

无法看到图片的人可以看到以下内容:

System.Exception

程序包更新、依赖或冲突验证失败。

无法安装包App.a5cd6ef3c.a895b.a4508.a96fd.af1634c30bb13,因为该包依赖于未找到的另一个包。此包要求安装由任何发布者发布的Microsoft.VCLibs.140.00.Debug框架的最低版本0.0.0.0。请随此包一起提供该框架。

在Microsoft.Expression.HostUtility.Platform.AppContainerProcessDomainFactory.CreateDesignerProcess(String applicationPath, String clientPort, Uri hostUri, IDictionary environmentVariables, Int32& processId, Object& processData)

在Microsoft.Expression.DesignHost.Isolation.Primitives.ProcessDomainFactory.ProcessIsolationDomain..ctor(ProcessDomainFactory factory, IIsolationBoundary boundary, AppDomainSetup appDomainInfo, FrameworkName targetFramework, String identifier, String baseDirectory)

在Microsoft.Expression.DesignHost.Isolation.Primitives.ProcessDomainFactory.CreateIsolationDomain(IIsolationBoundary boundary)

在Microsoft.Expression.HostUtility.Platform.AppContainerProcessDomainFactory.CreateIsolationDomain(IIsolationBoundary boundary)

在Microsoft.Expression.DesignHost.Isolation.Primitives.IsolationBoundary.Initialize()

在Microsoft.Expression.DesignHost.Isolation.Primitives.IsolationBoundary.CreateInstance[T](Type type)

在Microsoft.Expression.DesignHost.Isolation.IsolatedObjectFactory.Initialize()

在Microsoft.VisualStudio.ExpressionHost.Services.VSIsolationService.CreateObjectFactory(IIsolationTarget isolationTarget, IObjectCatalog catalog)

在Microsoft.Expression.DesignHost.Isolation.IsolationService.CreateLease(IIsolationTarget isolationTarget)

在Microsoft.Expression.DesignHost.Isolation.IsolationService.CreateLease(IIsolationTarget isolationTarget)

在Microsoft.Expression.DesignHost.Isolation.IsolationService.CreateLease(IIsolationTarget isolationTarget)

在Microsoft.Expression.DesignHost.IsolatedDesignerService.CreateLease(IIsolationTarget isolationTarget, CancellationToken cancelToken, DesignerServiceEntry& entry)

在Microsoft.Expression.DesignHost.IsolatedDesignerService.IsolatedDesignerView.CreateDesignerViewInfo(CancellationToken cancelToken)

在Microsoft.Expression.DesignHost.Isolation.IsolatedTaskScheduler.InvokeWithCulture[T](CultureInfo culture, Func`2 func, CancellationToken cancelToken)

在Microsoft.Expression.DesignHost.Isolation.IsolatedTaskScheduler.<>c__DisplayClass5`1.b__7()

在System.Threading.Tasks.Task`1.InnerInvoke()

在System.Threading.Tasks.Task.Execute()

我进入了App1.xaml.cs和MainPage.xaml.cs,发现App和MainPage分别没有定义InitializeComponent()。

该项目处于Visual Studio创建时的状态,我还没有改变任何内容!

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

0
0 Comments

今天我也遇到了同样的问题;为了复现这个问题,我只需要打开Visual Studio 2013 Update 4,创建一个空的Windows Phone 8.1应用,然后双击MainPage.xaml。

我通过以下方法解决了这个问题(结合了我在网上看到的解决方法):

1. 关闭所有的Visual Studio实例;

2. 删除%localappdata%\Microsoft\VisualStudio\12.0\Designer\ShadowCache目录下的所有文件;

3. 以管理员权限打开命令提示符,执行以下命令:

pushd %VS110COMNTOOLS%
icacls ..\IDE /grant *S-1-15-2-1:(OI)(F)
icacls ..\IDE /grant *S-1-15-2-1:(CI)(F)
icacls ..\IDE\PrivateAssemblies /grant *S-1-15-2-1:(OI)(F)
icacls ..\IDE\PrivateAssemblies /grant *S-1-15-2-1:(CI)(F)
icacls ..\IDE\PublicAssemblies /grant *S-1-15-2-1:(OI)(F)
icacls ..\IDE\PublicAssemblies /grant *S-1-15-2-1:(CI)(F)

4. 最后,重新启动电脑。这个方法适用于Windows 8.1 64位系统。

这个方法结合了这个答案,成功地解决了我的问题。

0
0 Comments

and make sure it is correctly set to the corresponding class name in your code-behind file.

If the x:class property is not set correctly, the InitializeComponent() method will not be recognized by the compiler, resulting in the error "Windows Phone 8 app does not contain a definition for InitializeComponent".

To fix this issue, open the XAML file for your page and locate the x:class attribute. Ensure that it is set to the correct class name. For example, if your code-behind file is MainPage.xaml.cs, the x:class attribute should be set to "MainPage".

If the x:class attribute is already set correctly, try cleaning and rebuilding your project. This can help resolve any build errors that may be causing the issue.

If the issue persists, it is possible that there is a problem with your project's build configuration. In this case, you can try manually deleting the bin and obj folders in your project's directory, and then rebuilding the project.

Additionally, make sure that your code-behind file (e.g., MainPage.xaml.cs) is correctly defined and contains the InitializeComponent() method. This method is responsible for initializing the XAML components and must be present in your code-behind file.

By checking the x:class property and ensuring it is set correctly, cleaning and rebuilding the project, and verifying the code-behind file, you should be able to resolve the "Windows Phone 8 app does not contain a definition for InitializeComponent" error.

0
0 Comments

在Windows Phone 8应用程序开发中,有时会遇到"Windows Phone 8 app does not contain a definition for InitializeComponent"的错误。出现这个错误的原因是XAML文件中的类名与对应的代码后台文件中的类名不匹配。

具体解决方法如下:

1. 确保XAML文件的类名与代码后台文件中的类名一致。

2. 检查XAML文件的开头标签中的x:Class属性值,它应该与代码后台文件中的类名相同。

3. 在代码后台文件的构造函数中调用InitializeComponent()方法来初始化控件,确保代码正确执行。

以下是一个示例代码:

XAML文件的开头标签:

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

代码后台文件:

public sealed partial class Bar : UserControl
{
    public Bar()
    {
        // 调用InitializeComponent()方法来初始化控件
        this.InitializeComponent(); 
    }
    ...
}

在这个示例中,需要将Namespace.Foo修改为Namespace.Bar,以匹配代码后台文件中的类名,从而消除错误。如果使用Page而不是UserControl,也应该具有相同的行为。

0