当前上下文中不存在错误但编译正常

2023-12-26

我遇到了一个我认为有点奇怪的问题。我收到两个“当前上下文中不存在”错误

Error   1   The name 'employeeDetails' does not exist in the current context    c:\users\kelly\documents\visual studio 2013\projects\insurance midam interface\insurance midam interface\mainwindow.xaml.cs 72  17  Insurance MidAm Interface
Error   2   The name 'searchBox' does not exist in the current context  c:\users\kelly\documents\visual studio 2013\projects\insurance midam interface\insurance midam interface\mainwindow.xaml.cs 80  34  Insurance MidAm Interface

然而,奇怪的是,该项目构建/编译得很好并且按预期运行。话虽这么说,由于这个错误,我没有在我想要的对象上获得 IntelliSense。

我最近对 ​​XAML 进行了广泛的编辑,因此我认为这与此有关,因为在此之前没有出现错误(实际上,当时不存在“employeeDetails”,但存在“searchBox”)。 Grid 和 TextBox 显然是非常基本的控件,因此我不知道我的引用或命名空间会出现什么错误。

我将真诚地感谢任何帮助。

相关CS:

private void viewButton_Click(object sender, RoutedEventArgs e) {


            DataRowView selectedValue = (DataRowView)employeeGrid.SelectedItem;
            MessageBox.Show(selectedValue.Row[0].ToString());

                employeeGrid.Visibility = Visibility.Collapsed;
                employeeDetails.Visibility = Visibility.Visible;



        }

        private void searchBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            String currentText = searchBox.Text;
            ds.Tables["Employees"].DefaultView.RowFilter = "last like '" + currentText + "*'";
        }
    }
}

和 XAML(对长度感到抱歉,但我担心如果我修剪它,我可能会删除故障代码):

<Window
        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" xmlns:local="clr-namespace:Insurance_MidAm_Interface" mc:Ignorable="d" x:Class="Insurance_MidAm_Interface.MainWindow"
        Title="View Employees" Height="700" Width="1000" Loaded="Window_Loaded" SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen" WindowState="Maximized">

    <StackPanel Name="outerPanel">
        <Grid Visibility="Collapsed" Name="employeeDetails" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"></ColumnDefinition>
                <ColumnDefinition Width="*"></ColumnDefinition>
                <ColumnDefinition Width="*"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"></RowDefinition>
                <RowDefinition Height="50"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
            </Grid.RowDefinitions>
            <StackPanel Orientation="Vertical" Grid.Row="0" Grid.Column="0">
                <Label Name="labelEmpSSN" Content="SSN: "></Label> <Label Name="labelEmpName" Content="Name: "></Label>
                <Label Name="labelEmpAddress" Content="Address:"></Label>
                <Label Name="labelEmpBirth" Content="DOB: "></Label>
                <Label Name="labelEmpGender" Content="Gender"></Label>
                <Label Name="labelEmpInsurance" Content="Insurance: "></Label>
                <Label Name="labelEmpDependents" Content="Dependents: "></Label>
                <Label Name="labelEmpLocation" Content="Location: "></Label>
                <Label Name="labelEmpVision" Content="Vision: "></Label></StackPanel>
            <StackPanel Orientation="Vertical" Grid.Row="0" Grid.Column="1">
                <Label Name="labelReportDate" Content="Date: " />
                <Label Name="labelReportAction" Content="Action: " />                
            </StackPanel>
            <StackPanel Orientation="Vertical" Grid.Row="0" Grid.Column="2">
                <Label Name="labelSpouseName" Content="Name: "></Label>
                    <Label Name="labelSpouseGender" Content="Gender: "></Label>
                <Label Name="labelSpouseSSN" Content="SSN: "></Label>
                <Label Name="labelSpouseBirth" Content="DOB: "></Label>
                <Label Name="labelSpouseAddress" Content="Address: "></Label>
                <Label Name="labelSpouseEmployed" Content="Employed by Company: "></Label>

            </StackPanel>
            <Label Grid.Row="1" Grid.Column="0" Content="Children"></Label>
            <Label Grid.Row="1" Grid.Column="1" Content="Life Beneficiaries"></Label>
            <Label Grid.Row="1" Grid.Column="2" Content="Vision Dependents"></Label>

            <StackPanel Orientation="Vertical" Grid.Column="0" Grid.Row="2">
                <Label Name="labelChildName1" Content="Name: "></Label>
                <Label Name="labelChildSSN1" Content="SSN: "></Label>
                <Label Name="labelChildGender1" Content="Gender: "></Label>
                <Label Name="labelChildBirth1" Content="DOB: "></Label>
                <Label Name="labelChildAddress1" Content="Address: "></Label>
                <StackPanel Orientation="Horizontal">
                    <Label Name="labelChildStep1" Content="Step:"></Label>
                    <Label Name="labelChildFost1" Content="Foster: "></Label></StackPanel>
                <StackPanel Orientation="Horizontal">
                    <Label Name="labelChildHandicap1" Content="Handicap: "></Label>
                    <Label Name="labelChildStudent1" Content="Student: "></Label>
                </StackPanel>
            </StackPanel>

            <StackPanel Orientation="Vertical" Grid.Column="0" Grid.Row="3">
                <Label Name="labelChildName2" Content="Name: "></Label>
                <Label Name="labelChildSSN2" Content="SSN: "></Label>
                <Label Name="labelChildGender2" Content="Gender: "></Label>
                <Label Name="labelChildBirth2" Content="DOB: "></Label>
                <Label Name="labelChildAddress2" Content="Address: "></Label>
                <StackPanel Orientation="Horizontal">
                    <Label Name="labelChildStep2" Content="Step:"></Label>
                    <Label Name="labelChildFost2" Content="Foster: "></Label>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <Label Name="labelChildHandicap2" Content="Handicap: "></Label>
                    <Label Name="labelChildStudent2" Content="Student: "></Label>
                </StackPanel>
            </StackPanel>

            <StackPanel Orientation="Vertical" Grid.Column="0" Grid.Row="4">
                <Label Name="labelChildName3" Content="Name: "></Label>
                <Label Name="labelChildSSN3" Content="SSN: "></Label>
                <Label Name="labelChildGender3" Content="Gender: "></Label>
                <Label Name="labelChildBirth3" Content="DOB: "></Label>
                <Label Name="labelChildAddress3" Content="Address: "></Label>
                <StackPanel Orientation="Horizontal">
                    <Label Name="labelChildStep3" Content="Step:"></Label>
                    <Label Name="labelChildFost3" Content="Foster: "></Label>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <Label Name="labelChildHandicap3" Content="Handicap: "></Label>
                    <Label Name="labelChildStudent3" Content="Student: "></Label>
                </StackPanel>
            </StackPanel>

            <StackPanel Orientation="Vertical" Grid.Column="0" Grid.Row="5">
                <Label Name="labelChildName4" Content="Name: "></Label>
                <Label Name="labelChildSSN4" Content="SSN: "></Label>
                <Label Name="labelChildGender4" Content="Gender: "></Label>
                <Label Name="labelChildBirth4" Content="DOB: "></Label>
                <Label Name="labelChildAddress4" Content="Address: "></Label>
                <StackPanel Orientation="Horizontal">
                    <Label Name="labelChildStep4" Content="Step:"></Label>
                    <Label Name="labelChildFost4" Content="Foster: "></Label>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <Label Name="labelChildHandicap4" Content="Handicap: "></Label>
                    <Label Name="labelChildStudent4" Content="Student: "></Label>
                </StackPanel>
            </StackPanel>

            <StackPanel Orientation="Vertical" Grid.Column="0" Grid.Row="6">
                <Label Name="labelChildName5" Content="Name: "></Label>
                <Label Name="labelChildSSN5" Content="SSN: "></Label>
                <Label Name="labelChildGender5" Content="Gender: "></Label>
                <Label Name="labelChildBirth5" Content="DOB: "></Label>
                <Label Name="labelChildAddress5" Content="Address: "></Label>
                <StackPanel Orientation="Horizontal">
                    <Label Name="labelChildStep5" Content="Step:"></Label>
                    <Label Name="labelChildFost5" Content="Foster: "></Label>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <Label Name="labelChildHandicap5" Content="Handicap: "></Label>
                    <Label Name="labelChildStudent5" Content="Student: "></Label>
                </StackPanel>
            </StackPanel>

            <StackPanel Orientation="Vertical" Grid.Column="1" Grid.Row="2">
                <Label Name="labelBeneficiaryName1" Content="Name: "></Label>
                <Label Name="labelBeneficiaryStatus1" Content="Status: "></Label>
                <Label Name="labelBeneficiarySSN1" Content="SSN: "></Label>
                <Label Name="labelBeneficiaryPercentage1" Content="Percentage: "></Label>
                <Label Name="labelBeneficiaryRelationship1" Content="Relationship"></Label>
            </StackPanel>

            <StackPanel Orientation="Vertical" Grid.Column="1" Grid.Row="3">
                <Label Name="labelBeneficiaryName2" Content="Name: "></Label>
                <Label Name="labelBeneficiaryStatus2" Content="Status: "></Label>
                <Label Name="labelBeneficiarySSN2" Content="SSN: "></Label>
                <Label Name="labelBeneficiaryPercentage2" Content="Percentage: "></Label>
                <Label Name="labelBeneficiaryRelationship2" Content="Relationship"></Label>
            </StackPanel>



            <StackPanel Orientation="Vertical" Grid.Column="1" Grid.Row="4">
                <Label Name="labelBeneficiaryName3" Content="Name: "></Label>
                <Label Name="labelBeneficiaryStatus3" Content="Status: "></Label>
                <Label Name="labelBeneficiarySSN3" Content="SSN: "></Label>
                <Label Name="labelBeneficiaryPercentage3" Content="Percentage: "></Label>
                <Label Name="labelBeneficiaryRelationship3" Content="Relationship"></Label>
            </StackPanel>


            <StackPanel Orientation="Vertical" Grid.Column="1" Grid.Row="5">
                <Label Name="labelBeneficiaryName4" Content="Name: "></Label>
                <Label Name="labelBeneficiaryStatus4" Content="Status: "></Label>
                <Label Name="labelBeneficiarySSN4" Content="SSN: "></Label>
                <Label Name="labelBeneficiaryPercentage4" Content="Percentage: "></Label>
                <Label Name="labelBeneficiaryRelationship4" Content="Relationship"></Label>
            </StackPanel>

            <StackPanel Orientation="Vertical" Grid.Column="2" Grid.Row="2">
                <Label Name="labelVisionName1" Content="Name: "></Label>
                <Label Name="labelVisonSSN1" Content="SSN: "></Label>
                <Label Name="labelVisionGender1" Content="Gender: "></Label>
                <Label Name="labelVisionBirth1" Content="DOB: "></Label>               

            </StackPanel>

            <StackPanel Orientation="Vertical" Grid.Column="2" Grid.Row="3">
                <Label Name="labelVisionName2" Content="Name: "></Label>
                <Label Name="labelVisonSSN2" Content="SSN: "></Label>
                <Label Name="labelVisionGender2" Content="Gender: "></Label>
                <Label Name="labelVisionBirth2" Content="DOB: "></Label>

            </StackPanel>

            <StackPanel Orientation="Vertical" Grid.Column="2" Grid.Row="4">
                <Label Name="labelVisionName3" Content="Name: "></Label>
                <Label Name="labelVisonSSN3" Content="SSN: "></Label>
                <Label Name="labelVisionGender3" Content="Gender: "></Label>
                <Label Name="labelVisionBirth3" Content="DOB: "></Label>

            </StackPanel>

            <StackPanel Orientation="Vertical" Grid.Column="2" Grid.Row="5">
                <Label Name="labelVisionName4" Content="Name: "></Label>
                <Label Name="labelVisonSSN4" Content="SSN: "></Label>
                <Label Name="labelVisionGender4" Content="Gender: "></Label>
                <Label Name="labelVisionBirth4" Content="DOB: "></Label>

            </StackPanel>

            <StackPanel Orientation="Vertical" Grid.Column="2" Grid.Row="6">
                <Label Name="labelVisionName5" Content="Name: "></Label>
                <Label Name="labelVisonSSN5" Content="SSN: "></Label>
                <Label Name="labelVisionGender5" Content="Gender: "></Label>
                <Label Name="labelVisionBirth5" Content="DOB: "></Label>

            </StackPanel>

        </Grid>
        <StackPanel Name="gridPanel">
        <StackPanel Orientation="Horizontal">
            <Label Content="Search (by last name):" Margin="10, 10"></Label>
            <TextBox Name="searchBox" Width="150" Margin="0,10" TextChanged="searchBox_TextChanged"></TextBox>
        </StackPanel>
        <DataGrid  AutoGenerateColumns="false" ItemsSource="{Binding}" x:Name="employeeGrid" HorizontalAlignment="Left" Margin="0" VerticalAlignment="Stretch" >
            <DataGrid.DataContext>
                <local:employee/>
            </DataGrid.DataContext>
            <DataGrid.Columns>
                <DataGridTextColumn Header="First" Binding="{Binding first}"/>
                <DataGridTextColumn Header="Last" Binding="{Binding last}"/>
                <DataGridTextColumn Header="SSN" Binding="{Binding ssn}"/>
                <DataGridTemplateColumn>
                    <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                            <Button Name="viewButton" Content="View Details" Click="viewButton_Click"></Button>
                    </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTextColumn Header="Employment Location" Binding="{Binding location}"/>
                <DataGridTextColumn Header="Email" Binding="{Binding email}"/>
                <DataGridTextColumn Header="Address" Binding="{Binding address}"/>
                <DataGridTextColumn Header="Insurance" Binding="{Binding decision}"/>
                <DataGridTextColumn Header="Vision" Binding="{Binding vision}"/>
                <DataGridTextColumn Header="Dependents" Binding="{Binding dependents}"/>
            </DataGrid.Columns>
        </DataGrid>
        </StackPanel>
    </StackPanel>
</Window>

除了清洁溶液之外,您还可以检查/清空溶液obj\debug文件夹。我可能是错的,但我认为 Visual Studio 设计器使用了其中的几个文件。

另外,根据this https://stackoverflow.com/questions/15121698/xaml-intellisense-not-working-after-adding-custom-xmlns,添加;assembly=在自定义命名空间声明的末尾,这样可以解决问题:

xmlns:local="clr-namespace:Insurance_MidAm_Interface;assembly="
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

当前上下文中不存在错误但编译正常 的相关文章

随机推荐

  • Facebook 表示有效 URL 不是有效 URL

    尝试将应用程序域添加到新应用程序 事情是域名是http the me http the me Facebook 不认为这是有效的 URL 有什么解决办法吗 你包括吗http 在那里 不应该有那个 只需使用the me作为您的域名 我刚刚尝试
  • 创建一个正常运行的 Response 对象

    出于测试目的 我尝试在 python 中创建一个 Response 对象 但事实证明它比听起来更难 我试过这个 from requests models import Response the response Response the r
  • Ant每次都会重建库项目

    我有一个 Android 项目 其中包含两个 Android 库项目 我正在使用命令ant debug构建该项目大约需要 1 分 20 秒 我算了一下 编译第一个android库项目用了17秒 编译第二个android库项目用了42秒 由于
  • 数据网格显示一个新行,但不显示任何后续行

    我有一个数据网格 其中一列显示组合框 目前 新行显示在现有行下方 正如预期的那样
  • 如何使用 EssentialAction

    我有一个自定义正文解析器 可将请求正文流式传输到 Amazon S3 实例 并且我想在上传文件之前进行验证 在请求的标头中 我可以访问内容大小和用户的身份验证令牌 通过这两件事 我可以验证用户是否有权上传文件 阅读 Play 的文档后 似乎
  • 获取请求客户端的 IP 地址(Soap 消息)

    我构建了一个 ASMX 服务 并在代码中处理来自 ELMAH 的错误日志 我将所有字段添加到数据库中 然后添加更多字段 其中之一是所请求客户端的 IP 地址 但我无法 请阅读 不知道如何 得到 我已经习惯了 string ipAddress
  • Java,不支持的类版本错误。我怎样才能解决这个问题

    我在 eclipse 中做作业 它没有报告任何错误 甚至没有警告 当我尝试从终端编译它时 出现以下错误 它在 eclipse 中运行和编译都很好 我认为这与java版本有关 无论如何要修复它或尝试绕过它 vedran vedran debi
  • 为什么不能在批处理 for 循环中使用问号?

    Preface 在编写单独的代码时 我遇到了 for 循环中问号的问题 如下所示 for循环中没有访问到问号 批处理文件 echo off for x in the quick brown fox do echo x Output the
  • 当邮件程序没有这样定义时,如何调用邮件程序上的类方法?

    在 Rails 中发送邮件时 通常会这样做 UserMailer password reset user deliver 但如果我们向内看UserMailer我们可以看到这个 def password reset user not self
  • 如何在我的 Xcode 项目中查看整个 SCM 历史记录?

    如果我查看项目信息中的 SCM 选项卡 我只会看到影响项目文件的提交 我在哪里可以获得整个项目的所有提交的列表 Xcode 4 转到 Organizer 右上角 Repositories 选择存储库 就在那里
  • 如何使用 Flink SQL 按事件时间对流进行排序

    我有一个故障DataStream
  • 如何在 angular-cli 项目中使用全局 scss 文件

    我是 Angular 4 和 Angular CLI 的新手 我找不到任何解决方案如何在整个应用程序中使用 root scss css 文件 因此 我的问题是 如何在项目中使用全局scss文件 创建一个styles文件夹中的src文件夹 然
  • 移动设备的 X/Y 触摸坐标

    我正在创建一个网络应用程序 我希望它可以在移动设备上使用 该应用程序的初始机制需要鼠标当前的 X Y 坐标 这不需要单击和拖动 只需在浏览器窗口周围移动鼠标即可 现在我一直在研究有关触摸和手势的各种 jQuery Javascript 库
  • Apache Pig:本地模式下使用简单 GROUP BY 时出现 OutOfMemory 异常

    当我尝试在一个微小的 3KB 随机生成的示例数据集上执行一个非常简单的 GROUP BY 时 我收到了 Pig 的 OutOfMemory 异常 小猪脚本 cat example pig raw LOAD example data USIN
  • Glassfish - 来自同一客户端的同时连接

    我正在构建一个必须处理来自一个客户端的最多 300 个请求的应用程序 我已尝试此链接上建议的所有配置 Glassfish 线程池 接受器线程 HTTP 最大连接数 https stackoverflow com questions 3309
  • 使用 JMeter 发送带有二进制正文的 HTTP 请求

    我正在尝试使用 JMeter 发送带有二进制内容的 HTTP 请求 在文档中 我发现我可以发送带有二进制内容的文件 我认为这对于我的需求来说不是一个好的解决方案 因为每个请求都有自己的二进制内容 下面是我用 Perl 编写的客户端示例 演示
  • 如何制作一个简单的密码页面[关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 小心 英语不好 我正在尝试创建一个页面 其中只有一个 小块 您可以在其中键入我设置的密码 如果您输入正确的密码并按 输入站点 按钮 您
  • GITLAB CI 管道未触发

    我已经为 GitLab CI CD 编写了这个 yml 文件 有一个已配置并正在运行的共享运行器 我是第一次这样做 不确定我哪里出错了 我正在进行的 Angular JS 项目 存储库上有一个 gulp 构建文件 并且在本地计算机上完美运行
  • 正则表达式 - 替换除 URL/URI 内的单词

    为 Web 应用程序编写全球化模块 我需要一个正则表达式来用另一个单词 翻译 替换一个单词的所有实例 除了在 URL URI 中找到的单词 编辑 我忘了提及我正在使用 Ruby 所以我不能使用 Lookbehind 根据 URI 正则表达式
  • 当前上下文中不存在错误但编译正常

    我遇到了一个我认为有点奇怪的问题 我收到两个 当前上下文中不存在 错误 Error 1 The name employeeDetails does not exist in the current context c users kelly