0
votes

I am working on a VSTO Outlook Addin for new mails. User can toggle image when he wants the mail saved.

Currently when the image is clicked i set a global bool to true.

private bool _state;
private void toggleBtn_Click(object sender, RibbonControlEventArgs e)
{
  if (_state) {
    _state = false;
  } else {
    _state = true;
  }
}

Which works ok until the user opens another new mail window before sending the first one.

How can i store the state per new mail window only?

Thank so much.

Solution

There are two ways to solve this problem.

One : User Properties Excellent blog on https://www.add-in-express.com/creating-addins-blog/2013/01/30/preserve-outlook-ribbon-controls-state/

Two: Use wrapper to store the state in classes Read more on https://msdn.microsoft.com/en-us/library/office/ff973716(v=office.14).aspx

2

2 Answers

0
votes

Not sure whether you can get the EntryId of the current mail being edited, if so, you can try to cache all the states into a dictionary, something like below

private Dictionary<string, bool> _states = new Dictionary<string, bool>();
private void toggleBtn_Click(object sender, RibbonControlEventArgs e)
{  
  MailItem ml;
  // get current MailItem
  // something like: MailItem ml = popupWindow.GetMail

  // default false
  if (!(_states.Keys.Contains(ml.EntryId))){
      _states[ml.EntryId] = false;
  }

  // toggle the state
  _states[ml.EntryId] = !_states[ml.EntryId];

}

however, you might want to handle the popup window closed event to remove the entry from the dictionary when user closes the popup (for example, email sent)

0
votes

Solution

There are two ways to solve this problem.

One : User Properties Excellent blog on https://www.add-in-express.com/creating-addins-blog/2013/01/30/preserve-outlook-ribbon-controls-state/

Two: Use wrapper to store the state in classes Read more on https://msdn.microsoft.com/en-us/library/office/ff973716(v=office.14).aspx