公共代表和在父实例化中看不到的事件 [英] Public delegate & event not seen in parent instantiation

查看:54
本文介绍了公共代表和在父实例化中看不到的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UserControl的部分类,编码如下:


公共部分类登录:System.Windows.Controls.UserControl

{

public delegate void StartingLoginHandler(string message);

public event StartingLoginHandler StartingLogin;


public Login()

{

InitializeComponent();

}


protected void OnStartingLogin(string message)

{

if(StartingLogin!= null)

{

StartingLogin(消息);

}

}

}


当我在父页面中实例化一个UserControl Login()对象时。我是

无法看到附加到它的事件。它不会在

事件中给出任何Intellisense,如果我继续输入并输入如下:


oLogin.StartingLogin + = oLogin。 StartingLoginHandler(delegate_method);


它不会编译;编译器只报告StartingLogin不存在。


请问解决方案或解决方法是什么?

-

Mike McAllister

I have a partial class of a UserControl coded as follows:

public partial class Login : System.Windows.Controls.UserControl
{
public delegate void StartingLoginHandler(string message);
public event StartingLoginHandler StartingLogin;

public Login()
{
InitializeComponent();
}

protected void OnStartingLogin(string message)
{
if (StartingLogin != null)
{
StartingLogin(message);
}
}
}

When I instantiate a UserControl Login() object in the parent page.xaml.cs I
cannot see the event to attach to it. It won''t give any Intellisense on the
event and if I just go ahead and type it in like:

oLogin.StartingLogin += oLogin.StartingLoginHandler(delegate_method);

it won''t compile; compiler just reports StartingLogin doesn''t exist.

What is the solution or a work-around please?
--
Mike McAllister

推荐答案




" Mike McAllister" < mi ************ @ newsgroup.nospamwrote in message

news:95 ****************** **************** @ microsof t.com ...
Hi,

"Mike McAllister" <mi************@newsgroup.nospamwrote in message
news:95**********************************@microsof t.com...

当我实例化UserControl Login()对象时父页面.xaml.cs



看不到附加到它的事件。它不会给

事件带来任何Intellisense

事件,如果我继续输入并输入如下:


oLogin.StartingLogin + = oLogin.StartingLoginHandler(delegate_method);


它不会编译;编译器只报告StartingLogin不存在。


请问解决方案或解决方法是什么?
When I instantiate a UserControl Login() object in the parent page.xaml.cs
I
cannot see the event to attach to it. It won''t give any Intellisense on
the
event and if I just go ahead and type it in like:

oLogin.StartingLogin += oLogin.StartingLoginHandler(delegate_method);

it won''t compile; compiler just reports StartingLogin doesn''t exist.

What is the solution or a work-around please?



当然无法看到它,因为它没有在UserControl中定义。


这是你应该的执行:


登录l = yourControl登录;

if(l!= null)

l.StartingLogin + = oLogin .StartingLoginHandler(delegate_method);

else

抛出新的异常(不正确的控件类型);

Of course it cannot be seen, as it''s not defined in UserControl.

This is what you should do:

Login l = yourControl as Login;
if ( l != null )
l.StartingLogin += oLogin.StartingLoginHandler(delegate_method);
else
throw new Exception( "Incorrect control type");


l.StartingLogin现在显示在Intellisense中。但是,以下两行

行抛出编译错误:


l.StartingLogin + =

oLogin.StartingLoginHandler(delegate_method) ;

l.StartingLogin + = l.StartingLoginHandler(delegate_method);


''System.Windows.Controls.UserControl''不包含

''StartingLoginHandler''


您有解决方案的建议吗?

-

Mike McAllister

Ignacio Machin(.NET / C#MVP)"写道:
l.StartingLogin now shows in Intellisense. However, both the following two
lines throw compiler errors:

l.StartingLogin +=
oLogin.StartingLoginHandler(delegate_method);
l.StartingLogin += l.StartingLoginHandler(delegate_method);

''System.Windows.Controls.UserControl'' does not contain a definition for
''StartingLoginHandler''

Do you have any suggestions for a work-around, please?
--
Mike McAllister
"Ignacio Machin ( .NET/ C# MVP )" wrote:




" Mike McAllister" < mi ************ @ newsgroup.nospamwrote in message

news:95 ****************** **************** @ microsof t.com ...
Hi,

"Mike McAllister" <mi************@newsgroup.nospamwrote in message
news:95**********************************@microsof t.com...

当我实例化UserControl Login()对象时父页面.xaml.cs



看不到附加到它的事件。它不会给

事件带来任何Intellisense

事件,如果我继续输入并输入如下:


oLogin.StartingLogin + = oLogin.StartingLoginHandler(delegate_method);


它不会编译;编译器只报告StartingLogin不存在。


请问解决方案或解决方法是什么?
When I instantiate a UserControl Login() object in the parent page.xaml.cs
I
cannot see the event to attach to it. It won''t give any Intellisense on
the
event and if I just go ahead and type it in like:

oLogin.StartingLogin += oLogin.StartingLoginHandler(delegate_method);

it won''t compile; compiler just reports StartingLogin doesn''t exist.

What is the solution or a work-around please?



当然无法看到它,因为它没有在UserControl中定义。


这是你应该的执行:


登录l = yourControl登录;

if(l!= null)

l.StartingLogin + = oLogin .StartingLoginHandler(delegate_method);

else

抛出新的异常(不正确的控件类型);


Of course it cannot be seen, as it''s not defined in UserControl.

This is what you should do:

Login l = yourControl as Login;
if ( l != null )
l.StartingLogin += oLogin.StartingLoginHandler(delegate_method);
else
throw new Exception( "Incorrect control type");




" Mike McAllister" < mi ************ @ newsgroup.nospamwrote in message

新闻:C6 ****************** **************** @ microsof t.com ...

"Mike McAllister" <mi************@newsgroup.nospamwrote in message
news:C6**********************************@microsof t.com...

l.StartingLogin现在显示在Intellisense中。但是,以下两行

行抛出编译错误:


l.StartingLogin + =

oLogin.StartingLoginHandler(delegate_method) ;

l.StartingLogin + = l.StartingLoginHandler(delegate_method);


''System.Windows.Controls.UserControl''不包含

''StartingLoginHandler''


您对解决方案有什么建议吗?
l.StartingLogin now shows in Intellisense. However, both the following two
lines throw compiler errors:

l.StartingLogin +=
oLogin.StartingLoginHandler(delegate_method);
l.StartingLogin += l.StartingLoginHandler(delegate_method);

''System.Windows.Controls.UserControl'' does not contain a definition for
''StartingLoginHandler''

Do you have any suggestions for a work-around, please?



将变量类型从UserControl更改为确切的派生类型,

以便能够使用其他方法/事件/属性。

Change the type of the variable from UserControl to the exact derived type,
to be able to use your additional methods/events/properties.


-

Mike McAllister


" Ignacio Machin(.NET / C# MVP)写道:
--
Mike McAllister
"Ignacio Machin ( .NET/ C# MVP )" wrote:

>

Mike McAllister < mi ************ @ newsgroup.nospamwrote in message
新闻:95 ********************** ************ @ microso ft.com ...
>Hi,

"Mike McAllister" <mi************@newsgroup.nospamwrote in message
news:95**********************************@microso ft.com...

当我在父
page.xaml.cs



看不到附加到它的事件。它不会给

事件带来任何Intellisense

事件,如果我继续输入并输入如下:


oLogin.StartingLogin + = oLogin.StartingLoginHandler(delegate_method);


它不会编译;编译器只报告StartingLogin不存在。


请问解决方案或解决方法是什么?
When I instantiate a UserControl Login() object in the parent
page.xaml.cs
I
cannot see the event to attach to it. It won''t give any Intellisense on
the
event and if I just go ahead and type it in like:

oLogin.StartingLogin += oLogin.StartingLoginHandler(delegate_method);

it won''t compile; compiler just reports StartingLogin doesn''t exist.

What is the solution or a work-around please?


当然无法看到它,因为它没有在UserControl中定义。

这是你应该做的:

登录l = yourControl as Login;
if(l!= null)
l.StartingLogin + = oLogin.StartingLoginHandler(delegate_method);

抛出新的异常(" ;不正确的控件类型");


Of course it cannot be seen, as it''s not defined in UserControl.

This is what you should do:

Login l = yourControl as Login;
if ( l != null )
l.StartingLogin += oLogin.StartingLoginHandler(delegate_method);
else
throw new Exception( "Incorrect control type");



这篇关于公共代表和在父实例化中看不到的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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