另一个 WPF 问题/问题。我制作了一个用户控件(称为编辑)。问题是在构建(以及在编辑器中)时,我收到以下编译错误:
“当前上下文中不存在名称‘InitializeComponent’。”
我还注意到两点:
(1) .xaml 文件(用户控件)的 Build Action 设置为 Page。代码隐藏文件的 Build Action 设置为 Compile。
(2)当我让程序运行时,尽管出现错误,但一切运行正常,但是此时我还没有将用户控件集成到应用程序中(即主窗口或任何不使用用户控件)此时应用程序的其他部分)。
这是 .xaml 代码:
<UserControl x:Class="Testing.Views.Edit"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Testing"
xmlns:views="clr-namespace:Testing.Views" >
<DockPanel Margin="5">
<Border DockPanel.Dock="Top">
<TextBlock>This is a User Control!</TextBlock>
</Border>
</DockPanel>
</UserControl>
代码隐藏:
using System;
using Testing;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
namespace Testing.Views
{
public partial class Edit : UserControl
{
public Edit()
{
InitializeComponent();
}
}
}
有人有想法吗?谢谢。