a.定义参数类类,继承自基类EventArgs
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;
namespace Calendar.Controls
{
public class AlmanacSelectionChangedEventArgs : EventArgs
{
private AlmanacSelectionChangedEventArgs() { }
//AlmanacInfo是一个封装了某些数据的结构体,它的对象就是索要传递的数据
internal AlmanacSelectionChangedEventArgs(AlmanacInfo selectedAlmanac)
{
SelectedAlmanac = selectedAlmanac;
}
public AlmanacInfo SelectedAlmanac { get; private set ; }
}
}
b.定义委托事件, 装载参数:
public event EventHandler<AlmanacSelectionChangedEventArgs> SelectionChanged;
private void OnDoneButtonClick(object sender, EventArgs args)
{
SelectionChanged(sender, new AlmanacSelectionChangedEventArgs (m_SelectedItem));
}
c.注册事件响应,在时间触发时通过EventHandler参数传递AlmanacInfo数据:
private void OnNavigated( object sender, NavigationEventArgs e)
{
AlmanacPickerPage almanacPage = e.Content as AlmanacPickerPage;
if (null != almanacPage)
{
almanacPage.SelectedItem = m_AlmanacSelected;
almanacPage.SelectionChanged += OnSelectionChanged;
}
}
private void OnSelectionChanged(object sender, AlmanacSelectionChangedEventArgs e)
{
m_AlmanacSelected = e.SelectedAlmanac;
}