View previous topic :: View next topic |
Author |
Message |
crogers
Joined: 30 Jul 2013 Posts: 2
|
Posted: Tue Jul 30, 2013 3:34 pm Post subject: WPF Preview cannot find StaticResource |
|
|
Globalizer is having trouble finding my style resource dictionary. It's located in a separate DLL project within the Solution I've added to Globalizer. I'm referencing it in the form like this Style="{StaticResource BDIWindow}". BDIWindow is a Style located in a ResourceDictionary in my solution's other project. Globalizer has no problem picking up the forms from this project, it just cannot load the style. If I remove all references to that style from my xaml forms it reads the wpf form just fine. What can I do so that Globalizer can load my style? Thanks! Colleen |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Wed Jul 31, 2013 10:05 am Post subject: |
|
|
I'm not sure exactly what you mean? Are you having problems previewing the form in Globalizer? Or is the issue with scanning and converting XAML resources? If you could put together a sample project that illustrates the problem and send a zipped copy to support@infralution.com together with the steps to replicate the issue that would help us a lot to resolve the issue. _________________ Infralution Support |
|
Back to top |
|
|
crogers
Joined: 30 Jul 2013 Posts: 2
|
Posted: Wed Jul 31, 2013 2:18 pm Post subject: |
|
|
Sorry I wasn't clear. I cannot view the form. I've sent you a sample application. Thank you. Colleen |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Sat Aug 03, 2013 5:33 am Post subject: |
|
|
Thanks for the sample application it has helped track down the issue. The problem is that when the Window is created in Globalizer for preview there is no Application object created and so the Application Resources are not initialized. You get an error because your window is using static application resources.
The workaround for this issue is to add an InitializePreview method to the App class that creates an instance of the App object there isn't already one. We also need to handle creation of the main window programatically by overriding the OnStartup method (instead of setting the StartupUri in the xaml). This is to avoid the App object creating a second instance of your main window when in preview mode.
The code below shows the App class:
Code: | public partial class App : Application
{
private static App _previewApp = null;
public static void InitializePreview()
{
if (App.Current == null && _previewApp == null)
{
_previewApp = new App();
_previewApp.InitializeComponent();
_previewApp.ShutdownMode = ShutdownMode.OnExplicitShutdown;
}
}
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
if (_previewApp == null)
{
new MainWindow().Show();
}
}
} |
Each window then calls the InitializePreview method in its constructor eg
Code: | public partial class MainWindow : Window
{
public MainWindow()
{
App.InitializePreview();
InitializeComponent();
}
} |
This enables windows that use static resources defined in App.xaml to be previewed in Globalizer. Unfortunately, because of how Globalizer creates the preview window any styles applied to the top level window are not shown in the preview.
We will see if we can fix the top level style issue and also whether there are any changes we could make to Globalizer to avoid the need for the additional code. _________________ Infralution Support |
|
Back to top |
|
|
|