Silverlight 4.0 能否在用户控件中创建事件,如果是,如何创建?
我已经创建了一个包含DatePicker的用户控件,我想在用户控件中创建一个链接到DatePicker DateChanged事件的事件。此自定义用户控件将在itemscontrol中使用。是。将公共事件添加到控件。然后添加查找附加到事件的代理的方法。如果有任何学员,请发起活动。下面是一个例子: 在用户控件中:Silverlight 4.0 能否在用户控件中创建事件,如果是,如何创建?,silverlight-4.0,Silverlight 4.0,我已经创建了一个包含DatePicker的用户控件,我想在用户控件中创建一个链接到DatePicker DateChanged事件的事件。此自定义用户控件将在itemscontrol中使用。是。将公共事件添加到控件。然后添加查找附加到事件的代理的方法。如果有任何学员,请发起活动。下面是一个例子: 在用户控件中: public partial class Controls_UserComments : System.Web.UI.UserControl { // the event del
public partial class Controls_UserComments : System.Web.UI.UserControl
{
// the event delegates may listen for
public event EventHandler CommentEditing;
protected void Page_Load(object sender, EventArgs e)
{
// handle an event in the user control and bubble the event up to any delegates
GridView_Comments.RowCancelingEdit += new GridViewCancelEditEventHandler(GridView_Comments_RowCancelingEdit);
}
void GridView_Comments_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView_Comments.EditIndex = -1;
GridView_Comments.DataBind();
// raise the event for attached delegates
if (CommentEditing != null)
CommentEditing(this, EventArgs.Empty);
}
}
<ppc:UserComments ID="UserComments_ObservationComments" runat="server"
OnCommentEditing="RefreshComments"
/>
现在,在使用用户控件的web表单中:
public partial class Controls_UserComments : System.Web.UI.UserControl
{
// the event delegates may listen for
public event EventHandler CommentEditing;
protected void Page_Load(object sender, EventArgs e)
{
// handle an event in the user control and bubble the event up to any delegates
GridView_Comments.RowCancelingEdit += new GridViewCancelEditEventHandler(GridView_Comments_RowCancelingEdit);
}
void GridView_Comments_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView_Comments.EditIndex = -1;
GridView_Comments.DataBind();
// raise the event for attached delegates
if (CommentEditing != null)
CommentEditing(this, EventArgs.Empty);
}
}
<ppc:UserComments ID="UserComments_ObservationComments" runat="server"
OnCommentEditing="RefreshComments"
/>
祝你好运