WPF 应用程序的当前上下文中不存在名称“InitializeComponent" [英] The name 'InitializeComponent' does not exist in the current context in WPF application

查看:33
本文介绍了WPF 应用程序的当前上下文中不存在名称“InitializeComponent"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 StackOverflow 上检查了所有类似的问题,但没有一个答案能解决我的问题.我只是在标题中看到错误.

I have checked all similar questions on StackOverflow, but none of the answers solved my problem. I simply get the error in title.

这是我的 MainVindow.xaml :

Here is my MainVindow.xaml :

<Window x:Class="CodeFirstMVVM.App.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:cm="clr-namespace:System.ComponentModel;assembly=System"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:vm="clr-namespace:CustomerOrder.App.ViewModel"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        mc:Ignorable="d"
        DataContext="{Binding Source={StaticResource Locator}, Path=CustomerView}"
        Title="MainWindow" Height="500" Width="900">
    <Grid>
        <Canvas>
            <TextBox Height="23" Canvas.Left="131" TextWrapping="Wrap"  Canvas.Top="51" Width="283" Name="txtName" Text="{Binding NameUI}"/>
            <DataGrid x:Name="maingrid" ItemsSource="{Binding Entities, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" SelectedItem="{Binding SelectedEntity}" AutoGenerateColumns="True" Canvas.Left="10" Canvas.Top="265">
                <DataGrid.Columns>
                    <DataGridTextColumn Binding="{Binding Name}" Header="Name" Width="200"></DataGridTextColumn>
                </DataGrid.Columns>
            </DataGrid>
            <DataGrid x:Name="ordergrid" ItemsSource="{Binding ElementName=maingrid, Path=SelectedItem.Orders}" AutoGenerateColumns="True" Canvas.Top="265" Canvas.Left="597">
                <DataGrid.Columns>
                    <DataGridTextColumn Binding="{Binding Explanation}" Header="Orders" Width="200"></DataGridTextColumn>
                </DataGrid.Columns>
            </DataGrid>
        </Canvas>

    </Grid>
</Window>

这是我的 App.xaml :

And here is my App.xaml :

<Application x:Class="CustomerOrder.App.App" 
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             xmlns:d ="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc ="http://schemas.openxmlformats.org/markup-compatibility/2006"
             StartupUri="MainWindow.xaml" 
             mc:Ignorable="d">
    <Application.Resources>
        <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" xmlns:vm="clr-namespace:CustomerOrder.App.ViewModel" />
    </Application.Resources>
</Application>

在 MainWindow.xaml.cs 上:

On MainWindow.xaml.cs :

namespace CustomerOrder.App
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }
}

你能告诉我如何解决这个问题吗?谢谢.

Can you tell me how to fix this? Thanks.

推荐答案

要修复它,请更改 xaml 的命名空间

To fix it, change the namespace of the xaml

<Window x:Class="CustomerOrder.App.MainWindow"

这篇关于WPF 应用程序的当前上下文中不存在名称“InitializeComponent"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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