NPalette.FromFile Type parameter example needed


https://www.nevron.com/Forum/Topic6581.aspx
Print Topic | Close Window

By Brad Swearingen - 12 Years Ago

I'm trying to provide custom palette support.  I'm on the 11.12.14.12 build.

The signature for NPalette.FromFile is this:

public static NPalette FromFile(    string filePath,   Type type)

Parameters

filePath
The fully qualified path to the specified file.
type
The type of the NPalette object requesting the load.

but the sample code you provide is this:

//copy this palette to another button
this.nButton2.Palette.Copy(NPalette.FromFile(@"C:\myPalette.xml");

This won't compile because its missing the "type" parameter.  (Its missing a right paren too.  )

How does one specify the "type" parameter?  I didn't find the "type" parameter definition helpful.  I tried typeof(NPalette) and that compiles but the call is failing for me.

By Nevron Support - 12 Years Ago
Hi Brad,

Thanks for notice this error in the documentation. We will fix it for the next release.

As a type parameter you should provide a typeof(NPalette) as you did.
The failing call may be caused because of a bad structure of the custom palette xml file.

Did you create your custom palette by calling NPalette.Save or SaveToFile method?
By Brad Swearingen - 12 Years Ago

Thanks for clarifying.  I first tried saving a palette through the "Save" button on the palette dialog launched via NUIManager.Palette.ShowEditor().  That produces the same .XML file that a call to NUIManager.Palette.SaveToFile produces.  Both seem like valid palette files to me and look the same.  I've attached the file I see.

If I make calls like below the FromFile always returns null for me.  I'm running on Windows7 using build 11.12.14.12.

NUIManager.Palette.SaveToFile(@"C:\temp\temppal2.xml");

NPalette pal = NPalette.FromFile(@"C:\temp\temppal2.xml", typeof(NPalette));

By Nevron Support - 12 Years Ago
Hi Brad,

In the version you have, when you save a palette in the xml file it creates tag named NUIPalette. The correct tag should be NPalette.
This problem is fixed in the current version.

You can rename this tag after save manually or you can get the latest version where this is fixed.
Please, excuse us for the inconvenience.


By Craig Swearingen - 12 Years Ago

Changing the tags from NUIPalette to NPalette in the .XML file did not work but changing the typeof to NUIPalette like below did.  Thanks.  Let me know if there is any problem with this:

NPalette pal = NPalette.FromFile(@"C:\temp\temppal2.xml", typeof(NUIPalette));