|
I have create a FormRegionFactory and a FormRegion (Separated) class. Everything is working fine and the form region is displayed when I open an appointment and click in it.
When I access the form region using Globals.FormRegions[activeInspector].MyFormRegion within the NewInspector event it comes back as null. It seems to only be instantiated when I click on the form region to display it. Is there any way I can have it instantiated on load of the inspector?
I am using VSTO 2008 with Visual Studio 2008 and Outlook 2007.
Thanks Nabil |
| Nab32 Thursday, October 08, 2009 8:56 PM |
Hello Nabil,
Welcome to MSDN forums!
As my understanding, your question is to access a form region when NewInspector event is triggered, right?
We could not access a Form Region in NewInspector event, if we exam the value of Globals.FormRegions.Count property we could find that it remains zero until the Form Region is going to be displayed, I think you already know this, this is how a Form Region works.
Could you please talk a little about your requirement? Why you need to access Form Region at that specific moment? If your purpose is to stop display a Form Region we could stop it from displayed in its FormRegionInitializing event. Please refer to this link: http://msdn.microsoft.com/en-us/library/bb608610.aspx
If you have any further question, please feel free to follow up.
Thanks.
Please remember to mark the replies as answers if they help and unmark them if they provide no help. |
| Tim Li Friday, October 09, 2009 7:03 AM |
The form region is never instantiated until it is displayed. I need to check some values in it for validation before item_write. The problem is if the user does not access it it is null.
After some thought maybe I should rephrase the question: how do I access the contents of a separated form region from within an inspector without first entering the region?
Thanks |
| Nab32 Friday, October 09, 2009 8:26 AM |
Hello Nab32,
We could not access the Form Region before it has been initialized, as this is a by designed behavior of Outlook, however, we could make some change to our program to get around this.
That is move the variables you need to check out of the Form Region class, for example declare them as class-level in ThisAddIn class, initialize them in ThisAddIn_Startup method, and after the Form Region is displayed, we could read the value of those variables into Form Region class to make sure the value is valid.
Thanks. Please remember to mark the replies as answers if they help and unmark them if they provide no help. |
| Tim Li Tuesday, October 13, 2009 10:17 AM |
Hi Nab,
I am writing to check the status of the issue on your side. Could you please let me know if the suggestion works for you or not? If you have any questions or concerns, please feel free to let me know. I will be more than happy to be of assistance.
Thanks.
Tim Li
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact EMAIL GONE
Please remember to mark the replies as answers if they help and unmark them if they provide no help. |
| Tim Li Thursday, October 15, 2009 7:08 AM |
Hi Tim,
Unfortunately it doesn't quite work. I am using an adjoining form region as a workaround. Even though the limited space is a problem the form is created straight away. I can't move my variables out as they are specific to the inspector. The only way I can think of is to store them in a dictionary and look them up using some identifier. It feels like a big hack though that I'd rather avoid. For now I'll stick to the form region unless you have any better ideas.
Thanks
Regards, Nabil |
| Nab32 Thursday, October 15, 2009 3:08 PM |
Hi, Could you give me a sample to demonstrate this problem? May be we could find another work around. Thanks.
Tim Li
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact EMAIL GONE
Please remember to mark the replies as answers if they help and unmark them if they provide no help. |
| Tim Li Friday, October 16, 2009 8:43 AM |
Within my form region I have a ViewModel object:
public class TestFormRegion : FormRegionControl
{
private TestViewModel _viewModel;
public TestFormRegion(FormRegion formRegion) : base(formRegion)
{
_viewModel = new TestViewModel();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
}
public TestViewModel ViewModel
{
get { return _viewModel; }
}
On item write I need to check if the viewmodel is dirty:
private void item_Write(ref bool cancel)
{
var inspector = Globals.ThisAddIn.Application.ActiveInspector();
var viewModel = Globals.FormRegions[inspector].TestFormRegion.ViewModel;
if (viewModel.IsDirty)
{
viewModel.Save();
}
}
However if the form region is separate the viewmodel is null unless I click on the formregion to display it first. |
| Nab32 Friday, October 16, 2009 12:02 PM |