为什么 Visual Studio 找不到我的 WPF InitializeComponent 方法? [英] Why can't Visual Studio find my WPF InitializeComponent method?

查看:40
本文介绍了为什么 Visual Studio 找不到我的 WPF InitializeComponent 方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很奇怪.

我有一个 XAML 文件,如下所示...

I have an XAML file that looks as follows...

<Window
    x:Name="window"
    x:Class="ix.Production.Title"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Title" Height="768" Width="1024"
    Loaded="window_Loaded">

    <Window.Resources>
   etc...

我的代码-旁边看起来如下...

And my code-beside that looks as follows...

using System;
using System.Windows;
using System.Windows.Media.Animation;
using System.Threading;

namespace ix.Production
{
    public partial class Title : Window
    {
        public Title()
        {
           InitializeComponent();
        }
    ....

此代码拒绝编译,因为 Visual Studio 坚持认为 InitializeComponent在当前上下文中不存在".

This code refuses to compile because Visual Studio insists that the InitializeComponent "does not exist in the current context."

我该如何解决这个问题?

How can I fix this problem?

推荐答案

看起来这是 Visual Studio 2008 中的一个问题.

Looks like this was a kink in Visual Studio 2008.

如果我创建一个新文件(即 Title2),复制/粘贴代码和 XAML,然后将所有Title"更改为Title2",一切都会再次正常.

If I create a new file (i.e. Title2), copy/paste the code and XAML, then change all 'Title' to 'Title2', everything works fine again.

这篇关于为什么 Visual Studio 找不到我的 WPF InitializeComponent 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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