Note that there are some explanatory texts on larger screens.

plurals
  1. POEvent fires more and more times
    primarykey
    data
    text
    <p>I have a silverlight mvvm application that loads main view with 2 user controls loaded into 2 ContentControls, one with listbox showing items and other with edit button. When i click edit button, 2 new user controls load into the ContentControls, one showing data to edit (EditData) and other having Save and Cancel button (EditAction). When i click save button, it raises an event that is defined in seperate GlobalEvents.cs class like: </p> <pre><code>public event EventHandler OnSaveButtonClicked; public void RaiseSaveButtonClicked() { this.OnSaveButtonClicked(this, EventArgs.Empty); } </code></pre> <p>and i subscribe to it in the other user control EditData, because i need to transfer that edited data via custom EventArgs, so i have put in the constructor of it's ViewModel: </p> <pre><code>this.globalEvents.OnSaveButtonClicked += (s, e) =&gt; SaveData(); </code></pre> <p>and in the Save data: </p> <pre><code>public void SaveData() { globalEvents.RaiseSaveData(EditedGuy); } </code></pre> <p>which raises another event that loads previous user controls into their ControlContent and shows edited data in list box. Thats all fine, but whenever i click on edit and then save again, it raises the event twice, and again 3 times, then 4 and so on. How can i make it to be raised only ONE time? I thought it could be because every time i click edit, a new instance of the user control is loaded and i dont know, maybe the subscription to the event stays, so i have tried to paste </p> <pre><code>this.globalEvents.OnSaveButtonClicked -= (s, e) =&gt; SaveData(); </code></pre> <p>to the Dispose() method but without success. How can i make this work?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload