Silverlight 中为Dialog添加委托
实现Dialog类
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using App;
using App.Data;
using App.Resources;
using App.Resources.Processes;
using App.Resources.Windows;
using App.Services;
using App.Windows;
using App.Windows.Controls;
using Zbs.Resources.Advertisements;
using Zbs.Windows.AdsManagement;
using Zbs.Resources.Accounts;
using Zbs.Resources.Organizations;
namespace Zbs.Windows.AdsManagement.AdsMethod
{
public class MethodAdEditorPage : UserControl
{
/// <summary>
/// 声明确认事件委托
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public delegate void DialogConfirm(object sender, RoutedEventArgs e);
/// <summary>
/// 声明取消事件委托
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public delegate void DialogCancel(object sender, RoutedEventArgs e);
//这是事件委托标准的声明方法,其实在参数里面我们可以不传,也可以是其他类型的。但是最好还是使用上面的声明方法,你可以继承EventArgs,来包装你要传送的其他任何参数。
Dialog mainLeftTreeViewDialog;
DataSelector<Account> dsAccount, dsCustomer;
DataSelector<CampaignStatus> dsCampaignStatus;
DataSelector<AdGroupStatus> dsAdGroupStatus;
public TextBox txtAccountName, txtCustomerName, txtCampaignName, txtAdGroupName;
public User currentLoginName { get; set; }
public string accountName { get; set; }
public string customerName { get; set; }
public string campaignName { get; set; }
public string adgroupName { get; set; }
/// <summary>
/// 确认绑定
/// </summary>
public event DialogConfirm dialogConfirm;
public event DialogCancel dialogCancel;
public MethodAdEditorPage()
{
}
//editor page 中左树的查询
void InitDialogSearchData()
{
//下拉列表,实现类似GridView功能
//dsAccount = new DataSelector<Account>(q => q.IsMcc == true,q => new object[]{q.Customer,q.CurAccendant.Person}).Do(o => {
// o.AddColumns(q => new object[]{q.CurAccendant.Person.Name,q.Name,q.IsMcc});
//});
//dsCustomer = new DataSelector<Account>(q => q.IsMcc == false,q => new object[]{q.Customer,q.CurAccendant.Person}).Do(o => {
// o.AddColumns(q => new object[] {q.Name,q.Customer.Name,q.CurAccendant.Name,q.Customer.Telephone,q.Address});
//});
txtAccountName = new TextBox();
txtCustomerName = new TextBox();
txtCampaignName = new TextBox();
txtAdGroupName = new TextBox();
dsCampaignStatus = new DataSelector<CampaignStatus>();
dsAdGroupStatus = new DataSelector<AdGroupStatus>();
}
public Dialog SearchMainLeftTreeView()
{
InitDialogSearchData();
//(form.DataSelector(r => r.Account).Do(o => {o.MinimumPrefixLength = 2; o.AddFilterMember(r=>r.GoogleID); o.AddColumns(r => new object[] {r.Name, r.GoogleID, }); })),
mainLeftTreeViewDialog = new Dialog
{
Title = "过滤查询",
Width = 800,
Height = 600,
Content = new AutoGrid(4, 80, 300, 80, 300)
{
Margin = new Thickness(5),
Children =
{
//new Label(){Content = "客服:"},dsAccount,
new Label(){Content = "客服姓名:"}.Do(o => o.Margin = new Thickness (5)),txtAccountName.GridColumnSpan(3),
new Label(){Height = 10}.GridColumnSpan(4),
//new Label(){Content = "客户:"},dsCustomer,
new Label(){Content = "客户姓名:"}.Do(o => o.Margin = new Thickness (5)),txtCustomerName.GridColumnSpan(3),
new Label(){Height = 10}.GridColumnSpan(4),
//new Label(){Content = "广告系列:"},dsCampaign,
new Label(){Content = "广告系列名称:"}.Do(o => o.Margin = new Thickness (5)),txtCampaignName,
new Label(){Content = "广告系列状态:"},dsCampaignStatus,
new Label(){Height = 10}.GridColumnSpan(4),
//new Label(){Content = "广告组:"},dsAdGroup,
new Label(){Content = "广告组名称:"}.Do(o => o.Margin = new Thickness (5)),txtAdGroupName,
new Label(){Content = "广告状态:"},dsAdGroupStatus,
new Label(){Height = 10}.GridColumnSpan(4),
new WrapPanel{
HorizontalAlignment = HorizontalAlignment.Center,
Margin = new Thickness(5),
Children = {
new App.Windows.Controls.Button(){Content = "确认", Width = 60, Height=23}.Do( o => o.Click += new RoutedEventHandler( MainLeftTreeViewDialogConfirm_Click)),
new App.Windows.Controls.Button(){Content = "取消" , Width = 60,Height=23}.Do(o => o.Click += new RoutedEventHandler(MainLeftTreeViewDialogCancel_Click)),
}
}.GridColumnSpan(2) .Do(o => o.VerticalAlignment = VerticalAlignment.Bottom)
}
}
};
return mainLeftTreeViewDialog;
}
void MainLeftTreeViewDialogConfirm_Click(object sender, RoutedEventArgs e)
{
//抛出事件,给所有相应者
this.dialogConfirm(sender, e);
}
void MainLeftTreeViewDialogCancel_Click(object sender, RoutedEventArgs e)
{
//抛出事件,给所有相应者
this.dialogCancel(sender, e);
}
public void dialogClose()
{
//SearchMainLeftTreeView().Close();这样的话就会重新new一个mainLeftTreeViewDialog了。
mainLeftTreeViewDialog.Close();
}
}
}
调用类
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
void btnLeftTreeViewSearch_Click(object sender, RoutedEventArgs e)
{
editor.SearchMainLeftTreeView().Show();
editor.dialogConfirm +=new Zbs.Windows.AdsManagement.AdsMethod.MethodAdEditorPage.DialogConfirm(editor_dialogConfirm);
editor.dialogCancel += new Zbs.Windows.AdsManagement.AdsMethod.MethodAdEditorPage.DialogCancel(editor_dialogCancel);
}
void editor_dialogConfirm(object sender, RoutedEventArgs e)
{
//UI.Alert(e.OriginalSource);
UI.Alert(editor.txtAccountName.Text);
editor.dialogClose();
}
void editor_dialogCancel(object sender, RoutedEventArgs e)
{
editor.dialogClose();
}