这很奇怪。
我有一个XAML文件如下所示...
<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...
我的旁边代码如下所示......
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“在当前上下文中不存在。”
如何解决这个问题?
最佳答案
我在复制粘贴 XAML 控件/窗口等时看到过这种情况发生。 InitializeComponent 方法存在于自动生成的相应 .g.cs 文件中。就我而言,复制粘贴后,XAML 的构建操作(在“属性”窗口中)更改为“资源”。我将其更改为“页面”,它开始正常工作。
我希望这会有所帮助。
帮助我解决这个问题的线程是 The name 'InitializeComponent' does not exist... 。
关于wpf - 为什么 Visual Studio 找不到我的 WPF InitializeComponent 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/954861/