事件 委托 简单应用

子页面向父页面传值。

子页面代码:

 public delegate void DeleteSelected(string id);
        public event DeleteSelected DoDelete;

        private void image1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (DoDelete != null)
            {
                Image img=sender as Image;
                DoDelete(img.Tag.ToString().Trim());
            }
           
        }

 

父页面代码:

{

GetTradeControl getTrade = new GetTradeControl(id, wareName, 1, price);
                        getTrade.DoDelete += new GetTradeControl.DeleteSelected(getTrade_DoDelete);
                        this.grd_get.Children.Add(getTrade);

}

 void getTrade_DoDelete(string id)
        {
            GetTradeControl gtc_ = null;
            foreach (GetTradeControl gtc in this.grd_get.Children)
            {
                if (gtc.Id == id)
                {
                    //this.grd_get.Children.Remove(gtc);
                    gtc_ = gtc;
                }
            }
            this.grd_get.Children.Remove(gtc_);
        }

posted @ 2013-08-05 15:22  碧落京豪  阅读(175)  评论(0编辑  收藏  举报