Customize Aspect

Top Previous Topic Next Topic  Print this topic

If we want to customize the aspect of an element without drawing it ourselves, we must create a new plugin which implements the IVisualObjectFactory interface.

 

Example

 

Create a new Silverlight Class Library.

 

Add a reference to Ecrion.Silverlight.

 

Implement the IAddin interface: create a new class named Addin which implements IAddin.

 

  public class Addin : IAddin

   {

      public Addin()

       {

       }

   

       // return a new instance of a IVisualObjectFactory

      public IVisualObjectFactory GetVisualObjectFactory()

       {

          return new VisualObjectFactory();

       }

 

       // return null because we don't have mouse event functionality

      public IActionHandler GetActionHandler()

       {

          return null;

       }

   }

 

 

Implement the IVisualObjectFactory interface: create a new class named VisualObjectFactory which implements IVisualObjectFactory.

 

  public class VisualObjectFactory : IVisualObjectFactory

   {

      public VisualObjectFactory()

       {

 

       }

 

      // return null because we don't want to create a visual element

      public DependencyObject GetVisualElement(ObjectData objectData)

       {

          return null;

       }

 

      /// <summary>

      /// this method change radius x and y properties for a rectangle data

      /// if ObjectData is not a RectangleData we do nothing

      /// </summary>

      /// <param name="objectData">an ObjectData</param>

      /// <returns>

      /// true because we don't want allow other plugins to make their own customizations

      /// </returns>

      public Boolean CustomizeObjectData(ObjectData objectData)

       {

          if (objectData.getObjectType == typeof(RectangleData))

           {

               ((RectangleData)objectData).RadiusX = 10;

               ((RectangleData)objectData).RadiusY = 10;

           }

 

          return false;

       }

   }

 

Build the project: put the DLL file in the Ecrion.Silverlight XAP archive and edit AppManifest.xaml to register the plugin.