Exemplo n.º 1
0
        async public static void MethodSnippets()
        {
            LayoutProjectItem layoutItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Layout Name"));
            Layout            layout     = await QueuedTask.Run(() => layoutItem.GetLayout());

            Element element = layout.FindElement("Group Element");


            #region Element_ConvertToGraphics
            //Convert a legend to a graphic and move the Title to the bottom of the legend and also move
            //the label in the contents pane to the bottom of the list.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                Legend leg          = layout.FindElement("Legend") as Legend;
                GroupElement result = leg.ConvertToGraphics().First() as GroupElement;
                Element firstElm    = result.Elements.First(); //Note: Bottom element is first in drawing order.
                foreach (Element elm in result.Elements)
                {
                    if (elm.Name == "Title")
                    {
                        elm.SetY(firstElm.GetY() - 0.25);          //Move title below other legend elements
                        elm.SetTOCPositionAbsolute(result, false); // Move Title item in TOC to bottom as well
                    }
                }
            });

            #endregion Element_ConvertToGraphics

            #region Element_GetSetAnchor
            //Change the element's anchor position

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                Anchor elmAnchor = element.GetAnchor();
                elmAnchor        = Anchor.CenterPoint;

                element.SetAnchor(elmAnchor); //You don't have to get to set; a shortcut would be: element.SetAnchor(Anchor.CenterPoint);
            });

            #endregion Element_GetSetAnchor

            #region Element_GetCustomProperty
            //Get a custom property that has been previously set.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                String custProp = element.GetCustomProperty("MyKeyString");
            });

            #endregion Element_GetCustomProperty

            #region Element_GetSetDefinition
            //Modify an element's CIM properties.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                CIMElement CIMElm = element.GetDefinition();

                //Modify a CIM value

                element.SetDefinition(CIMElm);
            });

            #endregion Element_GetSetDefinition

            #region Element_GetSetHeight
            //Modify an element's hieght.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                double elmHeight = element.GetHeight();
                elmHeight        = 11;

                element.SetHeight(elmHeight); //You don't have to get to set; a shortcut would be: element.SetHieght(11);
            });

            #endregion Element_GetSetHeight

            #region Element_SetLocked
            //Modify an element's locked state if it isn't already

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                if (!element.IsLocked)
                {
                    element.SetLocked(true);
                }
            });

            #endregion Element_GetSetLocked

            #region Element_GetSetLockedAspectRatio
            //Modify an element's aspect ratio.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                bool elmLocked = element.GetLockedAspectRatio();
                elmLocked      = false;                  //Turn off the locked state.

                element.SetLockedAspectRatio(elmLocked); //You don't have to get to set; a shortcut would be: element.SetLockedAspectRatio(false);
            });

            #endregion Element_GetSetLockedAspectRatio

            #region Element_GetSetRotation
            //Modify and element's rotation value.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                double elmRot = element.GetRotation();
                elmRot        = 22.5;

                element.SetRotation(elmRot); //You don't have to get to set; a shortcut would be: element.SetRotation(22.5);
            });

            #endregion Element_GetSetRotation

            #region Element_GetSetWidth
            //Modify an element's width.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                double elmWidth = element.GetWidth();
                elmWidth        = 8.5;

                element.SetWidth(elmWidth); //You don't have to get to set; a shortcut would be: element.SetWidth(8.5);
            });

            #endregion Element_GetSetWidth

            #region Element_GetSetX
            //Modify an element's X position.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                double elmX = element.GetX();
                elmX        = 4.25;

                element.SetX(elmX); //You don't have to get to set; a shortcut would be: element.SetX(4.25);
            });

            #endregion Element_GetSetX

            #region Element_GetSetY
            //Modify an element's Y position.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                double elmY = element.GetY();
                elmY        = 5.5;

                element.SetY(elmY); //You don't have to get to set; a shortcut would be: element.SetY(5.5);
            });

            #endregion Element_GetSetY

            #region Element_SetCustomProperty
            //Set a custom property on an element.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                element.SetCustomProperty("MyKeyString", "MyValueString");
            });

            #endregion Element_SetCustomProperty

            #region Element_SetName
            //Modify an element's name.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                element.SetName("New Name");
            });

            #endregion Element_SetName

            #region Element_SetTOCPositionAbsolute
            //Move an element to the top of the TOC

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                element.SetTOCPositionAbsolute(layout, true);
            });

            #endregion Element_SetTOCPositionAbsolute

            #region Element_SetTOCPositionRelative
            //Move a layout element above an existing layout element.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                element.SetTOCPositionRelative(element, true);
            });

            #endregion Element_SetTOCPositionRelative

            #region Element_SetVisible
            //Modify an element's visibility.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                element.SetVisible(true); //Turn it on / make visible.
            });

            #endregion Element_SetVisible
        }