1

In Silverlight I am using a profile window, with the option to delete the current profile in a hyperlink button. When the user hits the hyperlink button it takes them to a new form to confirm the deletion. Although the delete function has worked (i.e. the profile has been deleted form the datatbase), how can I get the first window to close when the user confirms?

This is what the hyperlink calls-

private void deleteProfile(object sender, RoutedEventArgs e)
    {

        deleteProfile dProfile = new deleteProfile();
        dProfile.textBlock1.Text = System.Convert.ToString("Delete " + lblMsg.Content);
        dProfile.Show();
    }

Then from there on dProfile I want to close the profileForm that the hyperlink sits on when the user clicks ok-

private void OKButton_Click(object sender, RoutedEventArgs e)
    {

        textBlock1.Text = "Profile Deleted.";
        profileForm.Close();

        Close();
    }

However the dProfile form only recognises profileForm when I create a new instance of it, how can I reference the current one I am using?

Ebikeneser
  • 2,582
  • 13
  • 57
  • 111

2 Answers2

2

There may be some other way, but you can try the following.

Create an event in Child Window

public event EventHandler SubmitClicked;

in your OKButton_Click event

private void OKButton_Click(object sender, RoutedEventArgs e)
{
    if (SubmitClicked != null)
    {
        SubmitClicked(this, new EventArgs());
    }
}

Do the following in the main window, attach event against the ChildWindow object

deleteProfile.SubmitClicked += new EventHandler(deleteProfile _SubmitClicked);

Then in the event you could do:

private void deleteProfile_SubmitClicked(object sender, EventArgs e)
{
    this.Close();
}

(Although its not required here, but you can use the process to pass values from Child window to parent window) Also check out this article

Habib
  • 219,104
  • 29
  • 407
  • 436
  • Out of interest, I have a listBox in the main page of the Silverlight app, which has a listBox that when a user selects an item, opens the profileForm, THEN the dProfile form being the third stage. Is it possible to refresh the listbox in the mainpage when the user clicks ok on the dProfile form? – Ebikeneser May 10 '12 at 14:58
  • just to say the listbox is linked up with a webservice call. – Ebikeneser May 10 '12 at 14:59
  • @Jambo If I understood it correctly, then sure, in the event on main page, instead of calling close, perform your routine to refresh ListView. – Habib May 10 '12 at 15:05
  • @Jambo, ummm, I am not sure whats going on, you might post a new question with your code in deleteProfile_SubmitClicked event or see if anyone from the community comes up with something – Habib May 10 '12 at 15:22
  • http://stackoverflow.com/questions/10537507/update-listbox-on-main-page-from-button-click-event-on-child-window – Ebikeneser May 10 '12 at 15:38
0

Make your self a property on the Delete Form. This property shall be: IsDeleted. Set it to True when the user clicks OK. Then when you return to your main window, read this property and close the current window.

Or get the result from the child window...

var viewModel = _srvLocator.GetInstance<YourViewModel>();
var inst = _srvLocator.GetInstance<IWindowManager>();

if (inst.ShowDialog(viewModel).Value)
{
Close();
}
st_stefanov
  • 1,147
  • 1
  • 10
  • 28