///This example references a PictureElement on a layout and changes the picture by setting a path to a file on disk using the
//Added references
using ArcGIS.Desktop.Core;
using ArcGIS.Desktop.Layouts;
using ArcGIS.Desktop.Framework.Threading.Tasks;
public class PictureElementExample
{
public static Task<bool> UpdatePictureElementAsync(string LayoutName, string PictureName, string PicturePath)
{
//Reference a layoutitem in a project by name
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals(LayoutName));
if (layoutItem == null)
return Task.FromResult(false);
return QueuedTask.Run<bool>(() =>
{
//Reference and load the layout associated with the layout item
Layout lyt = layoutItem.GetLayout();
//Reference a picture element by name
PictureElement picElm = lyt.FindElement(PictureName) as PictureElement;
if (picElm == null)
return false;
//Change the path to a new source
picElm.SetSourcePath(PicturePath);
return true;
});
}
}