View previous topic :: View next topic |
Author |
Message |
sheitman
Joined: 27 Apr 2010 Posts: 98
|
Posted: Tue Feb 22, 2011 1:55 pm Post subject: Preview issues |
|
|
Hi,
we have some serious problem with the preview.
Unfortunately our controls contains contains calls to query data from the database inside the constructor oder Load-Event/Load method where we get an exception in the designer.
To prevent this we added
Code: | if (LicenseManager.UsageMode != LicenseUsageMode.DesignTime) {
...
} |
to seperate this calls.
When we use Globalizers Preview we get this exceptions again so I guess the if statement fails here.
Is there some way you could change it or what we could do?
Best regards. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Tue Feb 22, 2011 11:27 pm Post subject: |
|
|
The Globalizer help has the following advice to ensure that forms and controls can be previewed:
Quote: | The default constructor (and OnLoad method) should not invoke code that depends on external initialization (since this may cause an exception when Globalizer.NET attempts to create the form/control without the initialization having occurred)
One simple coding technique to achieve the above conditions, for forms/controls that do need to access externally initialized data, is to provide a second constructor that takes the data object as a parameter. The form/control saves this in a member variable and each event handler that needs to access the data simply returns if the member variable is uninitialized (ie Null/Nothing). |
In your case because you already have a substantial amount of code and some checks in place to avoid similar issues with the visual studio designer an alternative approach may be easier.
Simply add the following static class to your project:
Code: | public static class DesignUtilities
{
private static _inDesignMode = true;
public static bool InDesignMode
{
get { return _inDesignMode; }
set { _inDesignMode = value; }
}
} |
In the main() method for your application, before creating any forms, you call:
Code: | DesignUtilities.InDesignMode = false; |
Then you can replace your existing checks with:
Code: | if (!DesignUtilities.InDesignMode) {
...
} |
This check will work with both Visual Studio designer and Globalizer previews. _________________ Infralution Support
Last edited by Infralution on Wed Feb 23, 2011 9:04 pm; edited 1 time in total |
|
Back to top |
|
|
sheitman
Joined: 27 Apr 2010 Posts: 98
|
Posted: Wed Feb 23, 2011 2:08 pm Post subject: |
|
|
Wow, thanks for the tip. I will give it a try. |
|
Back to top |
|
|
|