Parameters
- project
- The current ArcGIS Pro project to which the style has to be added.
- styleName
- Name of a core ArcGIS Pro style or the full path to a style file (.stylx) on disk that has to be added to the current project.
| Exception | Description |
|---|---|
| ArcGIS.Core.CalledOnWrongThreadException | This method must be called within the lambda passed to QueuedTask.Run |
{
var project = Project.Current;
await QueuedTask.Run(() =>
{
//For ArcGIS Pro system styles, just pass in the name of the style to add to the project
StyleHelper.AddStyle(project, "3D Vehicles");
//For custom styles, pass in the full path to the style file on disk
string customStyleToAdd = @"C:\Temp\CustomStyle.stylx";
StyleHelper.AddStyle(project, customStyleToAdd);
});
}
{
//Add the style to the current project
string stylePath = @"C:\MyStyles\OldStyle.stylx";
var project = Project.Current;
await QueuedTask.Run(() => StyleHelper.AddStyle(project, stylePath));
StyleProjectItem styleToUpgrade = Project.Current.GetItems<StyleProjectItem>().First(x => x.Path == stylePath);
//returns true if style can be upgraded
bool canUpgrade = styleToUpgrade.CanUpgrade;
}
{
//Add the style to the current project
string stylePath = @"C:\MyStyles\MyStyle.stylx";
var project = Project.Current;
await QueuedTask.Run(() => StyleHelper.AddStyle(project, stylePath));
StyleProjectItem styleToCheck = Project.Current.GetItems<StyleProjectItem>().First(x => x.Path == stylePath);
//returns true if style is read-only
bool isReadOnly = styleToCheck.IsReadOnly;
}
{
//Add the style to the current project
string stylePath = @"C:\MyStyles\MyStyle.stylx";
var project = Project.Current;
await QueuedTask.Run(() => StyleHelper.AddStyle(project, stylePath));
StyleProjectItem styleToCheck = Project.Current.GetItems<StyleProjectItem>().First(x => x.Path == stylePath);
//returns true if style matches the current Pro version
bool isCurrent = styleToCheck.IsCurrent;
}
{
bool success = false;
//Add the style to the current project
string stylePath = @"C:\MyStyles\OldStyle.stylx";
var project = Project.Current;
await QueuedTask.Run(() => StyleHelper.AddStyle(project, stylePath));
StyleProjectItem styleToUpgrade = Project.Current.GetItems<StyleProjectItem>().First(x => x.Path == stylePath);
//Verify that style can be upgraded
if (styleToUpgrade.CanUpgrade)
{
success = await QueuedTask.Run(() => StyleHelper.UpgradeStyle(styleToUpgrade));
}
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)