标签: initializecomponent

当前上下文中不存在名称"InitializeComponent"

如果我在Visual Studio 2010 SP1中创建一个新项目并选择"WPF应用程序"并尝试生成生成的应用程序,我会收到错误

当前上下文中不存在名称"InitializeComponent".

今天早上,当我尝试构建当前项目时,我遇到了类似的错误.昨天,编译和运行它没有问题.

我创建了一个新项目,每当我编译项目时都会收到错误.我刚刚将项目发送给了一位同事,他刚编译时没有任何错误.

怎么了?

wpf initializecomponent visual-studio-2010 visual-studio

358
推荐指数
20
解决办法
25万
查看次数

在源代码中排除代码分析规则

在我正在研究FxCop的项目中,我向Windows窗体设计器生成的InitializeComponent()方法显示了很多(我的意思是400多个)错误.大多数错误只是标签的Text属性的赋值.

我想在源代码中禁止这些方法,因此我将FxCop生成的抑制代码复制到AssemblyInfo.cs中,但它不起作用.

这是FxCop复制到剪贴板的属性.

[module: SuppressMessage("Microsoft.Globalization",
    "CA1303:DoNotPassLiteralsAsLocalizedParameters",
    Scope = "member",
    Target = "WindowsClient.MainForm.InitializeComponent():System.Void",
    MessageId = "System.Windows.Forms.Control.set_Text(System.String)")]
Run Code Online (Sandbox Code Playgroud)

任何人都知道正确的属性来压制这些消息?

PS:我使用的是Visual Studio 2005,C#,FxCop 1.36 beta.

code-analysis fxcop initializecomponent suppression visual-studio

19
推荐指数
1
解决办法
6547
查看次数

如何为InitializeComponent提供自定义代码?

在设计时修改ListView的列标题时,设计器会生成在运行时序列化列标题的代码:

private void InitializeComponent()
{
    this.listView1 = new System.Windows.Forms.ListView();
    this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
    this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
    this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
        this.columnHeader1,
        this.columnHeader2
    });
}
Run Code Online (Sandbox Code Playgroud)

表单设计者如何知道它应该为每个列调用构造函数,然后调用ListView的Columns属性的AddRange方法?我需要这个像我正在写的UserControl ListView.

c# user-controls initializecomponent designer winforms

11
推荐指数
1
解决办法
9128
查看次数

该程序集不允许部分信任的调用者.的InitializeComponent()

场景:我正在重构我们的一个应用程序以使用Nhibernate,并在几周之前遇到了这个问题.这个问题最初是与Nhibernate和Castle一起解决的,所以他们都重新编译了[assembly: AllowPartiallyTrustedCallers].但是,在对UI和代码库进行一些更改后,此错误再次出现.另外值得注意的是,我从Form_Main以编程方式控制加载我的用户控件.

问题:每当生成用户控件时,我都会收到以下错误.如果我注释掉加载,程序将运行.当我调试它结束于自动生成的InitializeComponent()函数.请注意,我无法进入该功能.

System.Security.SecurityException was unhandled
      Message="That assembly does not allow partially trusted callers."
      Source="A"
      GrantedSet=""
      PermissionState=""
      RefusedSet=""
      Url="file:///C:/Documents and Settings/ID/Desktop/A-NHIB2/bin/Debug/A.EXE"
      StackTrace:
           at A.UserControlCyber.InitializeComponent()
           at A.UserControlCyber..ctor() in C:\Documents and Settings\ID\Desktop\A-NHIB2\UserControl_Cyber.cs:line 34
           at A.FormMain.FormMainLoad(Object sender, EventArgs e) in C:\Documents and Settings\ID\Desktop\A-NHIB2\Form_Main.cs:line 30
           at System.Windows.Forms.Form.OnLoad(EventArgs e)
           at System.Windows.Forms.Form.OnCreateControl()
           at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
           at System.Windows.Forms.Control.CreateControl()
           at System.Windows.Forms.Control.WmShowWindow(Message& m)
           at System.Windows.Forms.Control.WndProc(Message& m)
           at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
           at System.Windows.Forms.ContainerControl.WndProc(Message& m)
           at System.Windows.Forms.Form.WmShowWindow(Message& m)
           at System.Windows.Forms.Form.WndProc(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           at …
Run Code Online (Sandbox Code Playgroud)

c# initializecomponent partial-trust .net-3.5

11
推荐指数
2
解决办法
2万
查看次数

如何自定义InitializeComponent的代码生成?更具体地说,如何对所有生成的代码进行后处理?

我正在尝试自定义Windows窗体设计器的代码生成InitializeComponent.MSDN文章"在.NET Framework可视化设计器中自定义代码生成"包含"控制代码生成"部分,该部分解释了如何执行此操作的基础知识.

我在上面的文章中密切关注了一个例子:

//using System.ComponentModel.Design.Serialization;

class SomeFormSerializer : CodeDomSerializer
{
    public override object Serialize(IDesignerSerializationManager manager,
                                     object value)
    {
        // first, let the default serializer do its work:
        var baseSerializer = (CodeDomSerializer)manager.GetSerializer(
                             typeof(Form).BaseType, typeof(CodeDomSerializer));
        object codeObject = baseSerializer.Serialize(manager, value);

        // then, modify the generated CodeDOM -- add a comment as the 1st line:
        if (codeObject is CodeStatementCollection)
        {
            var statements = (CodeStatementCollection)codeObject;
            statements.Insert(0, new CodeCommentStatement("CODEDOM WAS HERE"));
        }

        // finally, return the modified CodeDOM:
        return …
Run Code Online (Sandbox Code Playgroud)

c# serialization initializecomponent designer winforms

10
推荐指数
1
解决办法
3000
查看次数

为什么InitializeComponent是公共的

我的WPF用户控件的公共接口包含自动生成的InitializeComponent方法(包含在部分类中).这对我来说是一个惊喜,因为我预计这样的内部东西是私密的.

有没有办法从用户控件公共接口中删除InitializeComponent?

.net wpf user-controls initializecomponent

7
推荐指数
1
解决办法
1043
查看次数

自动优化Windows窗体InitializeComponent的性能

我有一个带有完整GUI的程序,需要大约750毫秒来加载,这要归功于InitializeComponent().经过一些研究,似乎有一些技术可以改善.NET在整个InitializeComponent部分中所用的时间.这些包括:

1:使用NGen或类似产品.

2:使用Speed-optimize Windows Forms应用程序中显示的多线程

3:其他技术,例如在添加它们之前设置控件属性,如优化InitializeComponent所示(需要1秒!).

不幸的是(1)只改进了我的情况大约20%,并且(2)和(3)实现起来很费时间,并且牺牲了完整GUI设计者的便利性.

是否有任何自动化解决方案可以直接获取源代码,并生成更短,更高效的解决方案InitializeComponent()

c# optimization performance initializecomponent winforms

6
推荐指数
1
解决办法
3274
查看次数

将构造函数参数传递给在 InitializeComponent 中创建的控件

InitializeComponent在表单上设置组件,但是对于我创建的用户控件,它调用默认构造函数,但我想在用户控件上调用我自己的构造函数(带参数)。样板代码说不要编辑内容,那么最好的方法是什么?

.net c# initializecomponent winforms

5
推荐指数
1
解决办法
2855
查看次数

在InitializeComponent()期间触发Form.OnResize

我在XP英文机器和XP日本机器上运行相同的UI代码.出于某种原因 - 这两台机器之间的行为是不同的:

在日语机器上,OnResize事件在InitializeComponent调用期间被触发(我认为是来自ResumeLayout函数).在英语机器上它没有.

我有一个OnResize的覆盖方法,它改变我定义的私有变量的值.由于组件未完全加载(Ctor仍在运行),这些变量为空,我得到一个异常.

我可以通过检查变量是否为null来修复代码,但我想了解为什么它首先被调用以及为什么它只在这台机器上发生.

在我通过网络搜索期间,我发现了其他人发布的相同问题,但没有解决方案(http://social.msdn.microsoft.com/Forums/en/winforms/thread/95aefae4-45d8-4ac5-a8f2- 6e2142dfb631).

onresize initializecomponent

4
推荐指数
1
解决办法
907
查看次数

使C#程序能够在任何操作系统上编译

我已经开始在c#2008上的XP 32位Windows操作系统上制作C#程序,现在我试图在Windows 7 64位操作系统中打开它.出现的问题是我无法在64位系统上运行c#2010中的程序,它不会超过Initialize Component(); 我的代码中的行.它出现了一个错误,"BadImageFormatException未处理",我认为这是因为我打开它的系统更改.对此有任何帮助我们都很棒.

谢谢

c# operating-system initializecomponent badimageformatexception

4
推荐指数
1
解决办法
450
查看次数

Xamarin上的黑屏

我有一个Xamarin便携式项目。
我调试的Xaml页面完全空白,在Android和IOS上的页面上都看不到任何组件。

我怎样才能解决这个问题?

注意:没有任何错误消息,页面正在打开,我看不到任何内容。
发生此错误出现了问题。当我修复它时,
尽管调试的页面在InitializeComponent错误之前仍在工作,但它们打开的页面还是空的。

任何帮助将不胜感激。

这是我的xaml:

<?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="AcikAkademi3.Layoutlar.GridOrnek3">

<Grid>
  <Grid.RowDefinitions>  
    <RowDefinition Height="*"></RowDefinition>
    <RowDefinition Height="*"></RowDefinition>
  </Grid.RowDefinitions>

  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="*"></ColumnDefinition>
    <ColumnDefinition Width="*"></ColumnDefinition>
    <ColumnDefinition Width="Auto"></ColumnDefinition>
  </Grid.ColumnDefinitions>

  <Label BackgroundColor="Red" Text="0,0" Grid.Column="0" Grid.Row="0">
  </Label>
  <Label BackgroundColor="Blue" Text="1,0" Grid.Column="1" Grid.Row="0">
  </Label>
  <Label BackgroundColor="Yellow" Text="Aç?k Akademi" Grid.Column="2" Grid.Row="0"></Label>

  <Label BackgroundColor="White" Text="0,1" Grid.Column="0" Grid.Row="1">
  </Label>
  <Label BackgroundColor="Silver" Text="1,1" Grid.Column="1" Grid.Row="1">
  </Label>
  <Label BackgroundColor="Lime" Text="2,1" Grid.Column="2" Grid.Row="1">
  </Label>

</Grid>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)

这是我的CS:

using System;
using System.Collections.Generic;
using …
Run Code Online (Sandbox Code Playgroud)

xaml initializecomponent xamarin.ios xamarin.android xamarin

2
推荐指数
1
解决办法
3037
查看次数

初始化组件错误C#

所以我完成了我的程序,并尝试在顶部编辑一些小东西,并开始收到错误,无法更改它们.这是代码:

namespace FinalProject
{
    public partial class Form : Form
    {
        public Form();
        {
           InitializeComponent();

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我更改了Form:Form部分,然后它InitializeComponent();变成了一个错误.试图改变它,它仍然显示错误.撤消不是一个选项,我相信这是一个简单的解决方案.

c# initializecomponent

1
推荐指数
1
解决办法
4048
查看次数

出现错误:“名称 InitializeComponent 在当前上下文中不存在”,在每个 xaml.cs 类(Xamarin Forms)中

因此,突然间,常见错误“名称 InitializeComponent 在当前上下文中不存在”出现在我所有解决方案中的每个 xaml.cs 类中,我已经尝试了针对此问题的多种常见解决方案,但似乎都不起作用。

\n

继承内容视图的 xaml.cs:

\n
using System;\nusing System.Collections.Generic;\nusing Xamarin.Forms;\n\nnamespace FirstApp.Renderers\n{\n    public partial class CustomExpansibleMenu : ContentView\n    {\n        public CustomExpansibleMenu()\n        {\n//Error here\n            InitializeComponent();\n        }\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

从内容页继承的 xaml.cs:

\n
using System;\nusing System.Collections.Generic;\nusing System.Threading.Tasks;\nusing FirstApp.Services;\nusing Xamarin.Essentials;\nusing Xamarin.Forms;\n\nnamespace FirstApp.Pages\n{\n    public partial class ChatMenuPage : ContentPage\n    {\n        private NavigationService navigation;\n        public static double numPixelsW;\n        public static double numPixelsH;\n\n        public ChatMenuPage()\n        {\n            numPixelsH = DeviceDisplay.MainDisplayInfo.Height / DeviceDisplay.MainDisplayInfo.Density;\n            numPixelsW = DeviceDisplay.MainDisplayInfo.Width / DeviceDisplay.MainDisplayInfo.Density;\n\n            navigation = new NavigationService();\n\n//Error here \n            InitializeComponent();\n\n//Another error here, …
Run Code Online (Sandbox Code Playgroud)

c# xaml initializecomponent xamarin xamarin.forms

1
推荐指数
1
解决办法
8534
查看次数