问题描述:
在开发过程中,我建立了MianPanel,其中有很多的控件,为了方便管理,我使用了UIElement来管理我的Bind。其中,用ButtonLlist来管理我的按钮控件,用其他的panel来管理我的折线图空间。此时ButtonList与panel是无法进行数据交换的,只能通过MainPanel来传递数据给其下面的UIElement。
解决办法:
作为初学者,记录一下使用委托这种方式,来进行在ButtonLlist中定义的委托,可以调用在MainPanel中定义的方法,这样就实现了点击按钮之后 通过MainPanel来给折线图传递参数。
相关代码
1.在ButtonLIst上定义委托,我使用的是Action
//定义委托
public Action GetData;
2.在MainPanel上写委托调用方法
public void UpdateData()
{
//在这里写业务逻辑
}
3.在MainPanel上实现方法
ButtonList.GetData = UpdateData;
4.在ButtonLIst上实现委托
GetData();
这样就解决了问题