Hello,
I`m currently in trouble with searching a StyleProjectItem for a specific ColorRamp / ColorRampStyleItem.
First I have to say, I want to ship my style-file (*.stylx) with my addin project. So I created a *.stylx file and saved it under my addin project root folder.
I`m also shipping the config.json with my project and for that I added both existing items into my VS project and set "always copy" for both files.
That all seems to work fine. I can load the style into the project and I can get it from project by style-name but when I search for ColorRamps in the style by searchString I always get null.
string stylePath = Path.Combine(JsonReader.addinAssemblyLocation(), "max_honsell_styles.stylx");
var styleLoaded = Project.Current.AddStyleAsync(stylePath);
StyleProjectItem style = Project.Current.GetItems<StyleProjectItem>().First(x => x.Name == "max_honsell_styles");
IList<ColorRampStyleItem> colorRamps = style.SearchColorRampsAsync(MY SEARCH STRING AS PART OF COLOR RAMP NAME) as IList<ColorRampStyleItem>;
I have no idea what could be wrong here.
I also looked into the Assembly Cache, the stylx file is there! If I copy it and load it into ArcGIS pro manually, I see the colorScheme in it with the right name.
Any idea would be very appreciated.
Solved! Go to Solution.
Hi Richard
You have to "Await" the AddStyleAsync call. When you do that, your custom style is loaded into Pro and then you can work with it. The following code worked for me:
string stylePath = Path.Combine(@"C:\Users\user\Documents\StyleGeoNetTest\max_honsell_styles.stylx");
await Project.Current.AddStyleAsync(stylePath);
StyleProjectItem style = Project.Current.GetItems<StyleProjectItem>().First(x => x.Name == "max_honsell_styles");
Thanks
Uma
Hi Richard
You have to "Await" the AddStyleAsync call. When you do that, your custom style is loaded into Pro and then you can work with it. The following code worked for me:
string stylePath = Path.Combine(@"C:\Users\user\Documents\StyleGeoNetTest\max_honsell_styles.stylx");
await Project.Current.AddStyleAsync(stylePath);
StyleProjectItem style = Project.Current.GetItems<StyleProjectItem>().First(x => x.Name == "max_honsell_styles");
Thanks
Uma
Hi Uma,
thank you for that hint. Somehow I got the style file also when I didn't await it. Anyway now I await the style but I still cannot find color ramps in it, that's my major problem.
Richard
Hi Uma,
you were indeed right with the await keyword. I was missing it at style.SearchColorRampsAsync() too!
Thank you again for this solution.
I think it will still take a while for me to understand this whole async/await QueuedTask CourseGrained/FineGrained thing .
Richard