solaris783
Topic Author
Posts: 5
Joined: 07 Oct 2019, 03:41

How to track down Xaml path errors?

10 Oct 2019, 23:36

I have this line in my xaml:
<ResourceDictionary  Source="NocturnalStyle.xaml"/>
I get the error:
[NOESIS/I] 'NoesisTheme.xaml' loaded
[NOESIS/E] Xaml provider not set
[NOESIS/E] <memory>(13): Xaml not found 'NocturnalStyle.xaml'
The xaml calling NocturnalStyle works in VS Blend and in Kaxaml -- those design tool load the resource just fine. The file "NocturnalStyle" is in the same folder as the main xaml calling it. I also tried to put it in other places like where the VS project is or executable as well as putting an absolute path there, but Noesis never finds it. I re-wrote the line to be more explicit as well:
<ResourceDictionary  Source="/IntegrationGLUT-blend;component/NocturnalStyle.xaml"/>
which also works in VS Blend, but not in Noesis (still can't find it).

The "Xaml provider not set" was fixed with the addition of:
GUI::SetXamlProvider(MakePtr<NoesisApp::LocalXamlProvider>(""));
but it still can't find NocturnalTheme.xaml.

I also tried:
GUI::SetXamlProvider(MakePtr<NoesisApp::LocalXamlProvider>(""));
Noesis::Ptr<Noesis::Grid> main = Noesis::GUI::LoadXaml<Noesis::Grid>("../IntegrationGLUT-blend/UserControl1.xaml");
which yielded the same results.

How do I fix this?

Tags:
 
solaris783
Topic Author
Posts: 5
Joined: 07 Oct 2019, 03:41

Re: How to track down Xaml path errors?

11 Oct 2019, 21:09

I'm not sure if I'm doing this right but I solved it by pre-loading the resources the xamls reference. a) I thought that because the error said, "xaml not found" that it couldn't find the file. It seems like it doesn't look for a file, it looks for a resource in memory that's supposed to be already loaded. b) I thought that if a xaml file referenced another xaml file, that LoadXaml would (should) load the second one automatically from disk. c) literally no examples of this workflow found in the examples or online documentation.

Here's the code:
	GUI::SetFontProvider(MakePtr<NoesisApp::LocalFontProvider>(""));
	GUI::SetTextureProvider(MakePtr<NoesisApp::LocalTextureProvider>(""));
	GUI::SetXamlProvider(MakePtr<NoesisApp::LocalXamlProvider>(""));
	// the following path is relative to where the .vcxproj is:
	Noesis::Ptr<Noesis::ResourceDictionary> noct = Noesis::GUI::LoadXaml<Noesis::ResourceDictionary>("../IntegrationGLUT-blend/NocturnalStyle.xaml"); 
	Noesis::Ptr<Noesis::Grid> main = Noesis::GUI::LoadXaml<Noesis::Grid>("../IntegrationGLUT-blend/UserControl1.xaml");
and the xaml just needs this for referencing my Style file:
<ResourceDictionary  Source="NocturnalStyle.xaml"/>
 
User avatar
sfernandez
Site Admin
Posts: 1918
Joined: 22 Dec 2011, 19:20

Re: How to track down Xaml path errors?

13 Oct 2019, 13:41

Noesis needs a XamlProvider to load xaml resources as you found.
The LocalXamlProvider looks for files in disk by appending the specified path root to the current directory, so usually you have to place your xaml files next to the .exe file in order to find them.

For example, if you have:
- XamlTest.exe
+ Data/
--- MainWindow.xaml
--- NocturnalStyle.xaml
And set the LocalXamlProvider as:
GUI::SetXamlProvider(MakePtr<NoesisApp::LocalXamlProvider>(""));
To load the MainWindow if the current directory is where application .exe is found, you should write:
Noesis::Ptr<Noesis::Grid> main = Noesis::GUI::LoadXaml<Noesis::Grid>("Data/MainWindow.xaml");
And if MainWindow.xaml references inside the xaml the NocturnalStyle.xaml, it can use a relative path:
<Grid x:Class="XamlTest.MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid.Resources>
      <ResourceDictionary Source="NocturnalStyle.xaml"/>
    </Grid.Resources>
    ...
</Grid>
The xaml parser by using the Uri converter will automatically convert the relative path "NocturnalStyle.xaml" to "Data/NocturnalStyle.xaml" and pass that to the LocalXamlProvider.

There is no need to have resources pre-loaded in memory, just place them in the appropriate directories according to providers configuration.

Who is online

Users browsing this forum: Google [Bot] and 1 guest