Step 1: add the event handler to OK and the Cancel button
private void btnOK_Click(object sender, RoutedEventArgs e)
{
}
private void btnCancel_Click(object sender, RoutedEventArgs e)
{
}
Add a public property in the UserControl1.xaml.cs file to share the text field value with the host
public string UserName
{
get { return txtName.Text; }
set { txtName.Text = value; }
}
"" "", Windows Form.
public event EventHandler OkClick;
public event EventHandler CancelClick;
, .
private void btnOK_Click(object sender, RoutedEventArgs e)
{
if (OkClick != null)
OkClick(this, e);
}
private void btnCancel_Click(object sender, RoutedEventArgs e)
{
if (CancelClick != null)
CancelClick(this, e);
}
2: WPF Windows
OKClick CancelClick
_WPFUserControl.OkClick += new EventHandler(OnOkHandler);
_WPFUserControl.CancelClick += new EventHandler(OnCancelHandler);
. UserName OK, , .
protected void OnOkHandler(object sender, EventArgs e)
{
MessageBox.Show("Hello: " +_WPFUserControl.UserName + " you clicked Ok Button");
}
protected void OnCancelHandler(object sender, EventArgs e)
{
MessageBox.Show("you clicked Cancel Button");
}
:
http://a2zdotnet.com/View.aspx?Id=79