/ *类库 / / calcEventArgs.cs * /
namespace calc1
{
public class calcEventArgs
{
}
public class CalculationCompletedEventArgs : System.EventArgs
{
public string StringValue { get; set; }
public int IntegerValue { get; set; }
}
}
/ * CalcMain.xaml.cs * /
namespace calc1
{
public partial class CalcMain : Page
{
public delegate void CalcEventHandler(object sender, CalculationCompletedEventArgs e);
public event CalcEventHandler CalculateCompletedEvent;
public CalcMain()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
CalculationCompletedEventArgs pArgs = new CalculationCompletedEventArgs();
pArgs.StringValue = "1 + 1";
pArgs.IntegerValue = 2;
CalcEventHandler eh = CalculateCompletedEvent;
if (eh != null) eh(this, pArgs);
}
}
}
/ * EventTest应用程序* /
namespace EventTest
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
calc1.CalcMain c = new calc1.CalcMain();
c.CalculateCompletedEvent += new calc1.CalcMain.CalcEventHandler(CalcfromPage);
}
private void CalcfromPage(object sender, calc1.CalculationCompletedEventArgs e)
{
MessageBox.Show(e.StringValue + " = " + e.IntegerValue.ToString());
}
private void Button_Click(object sender, RoutedEventArgs e)
{
fraMainScreen.Navigate(new Uri("pack://application:,,,/calc1;component/CalcMain.xaml", UriKind.Absolute));
}
}
}
这是我的代码 我有问题 ... CalcEventHandler eh = CalculateCompletedEvent
CalculateCompletedEvent始终为null ..
帮助.. 谢谢。 ^^