Select to view content in your preferred language

How to create Dash Dot Dot Border for custom fill symbol?

1484
4
06-10-2012 10:58 PM
RomanGeoda
New Contributor
I would like to make a brush with a style of "dash dot dot" in silverlight.
I actually want to accomplish a "dash dot dot" border around a custom graphic (apply it to a FillSymbol.BorderBrush property). Is there a way to do this?

Thanks,
Roman.
0 Kudos
4 Replies
DominiqueBroux
Esri Frequent Contributor
You can get the result you are expecting by using a CartographicLineSymbol and setting the DashArray.
You will find samples in the symbol gallery : http://help.arcgis.com/en/webapi/silverlight/samples/SymbolGalleryWeb/start.htm
0 Kudos
JoeHershman
MVP Alum
And if you have not seen it there is not better example of creating custom symbology than Dominques http://www.arcgis.com/home/item.html?id=1e432da7e74f4402bd43a5863167022d#
Thanks,
-Joe
0 Kudos
RomanGeoda
New Contributor
Thank you for your help.
I'll have a look at these two links. Looks very promising!

Roman.
0 Kudos
AvronPolakow
Occasional Contributor
// Here's all the code you need

using ESRI.ArcGIS.Client;
    // Custom Symbol with dots and dashes on demand
    Graphic graphic = new Graphic()
    {
     Geometry = polygon1,
     Symbol   = new AnimatedPolygonSymbol(_color, _width, _line)
    };


using System.Windows.Markup;
using System.Windows.Controls;

  #region Special Symbols 
  /// <summary>
  /// AnimatedPolygonSymbol class for AnimatedPolygon
  /// </summary>
  public class AnimatedPolygonSymbol : FillSymbol // LineSymbol
  {
   /// <summary>
   ///
   /// </summary>
   /// <param name="astrColor"></param>
   /// <param name="astrThickness"></param>
   /// <param name="astrType">Array of dots and dashes</param>  <!-- 3,3,5,4 etc -->
   public AnimatedPolygonSymbol(string astrColor, string astrThickness, string astrType) : base()
   {
    string lstrTemplate  = AnimatedPolygon(); 

    astrType               =  (astrType == "") ? "3,3" : astrType;
    lstrTemplate          = lstrTemplate.Replace("MyColor",        (astrColor     == "" ? "Red" : astrColor));
    lstrTemplate          = lstrTemplate.Replace("MyThickness", ((astrThickness == "" ) ? "3" : astrThickness));
    lstrTemplate          = lstrTemplate.Replace("MyType",        astrType);

    this.ControlTemplate = (ControlTemplate) XamlReader.Load(lstrTemplate);
   }

   public string AnimatedPolygon()
   {
    string lstr = "";

    lstr += "<ControlTemplate \n";
    lstr += "    xmlns=\"http://schemas.microsoft.com/client/2007\" \n";
    lstr += "    xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" \n";
    lstr += "    xmlns:sys=\"clr-namespace:System;assembly=mscorlib\" \n";
    lstr += "    xmlns:vsm=\"clr-namespace:System.Windows;assembly=System.Windows\">\n";

    lstr += "    <Grid>\n";
    lstr += "     <vsm:VisualStateManager.VisualStateGroups>\n";
    lstr += "      <vsm:VisualStateGroup x:Name=\"CommonStates\">\n";
    lstr += "       <vsm:VisualState x:Name=\"Normal\">\n";
    lstr += "        <Storyboard RepeatBehavior=\"Forever\">\n";
    lstr += "         <DoubleAnimation \n";
    lstr += "            BeginTime=\"0:0:0\" \n";
    lstr += "            Storyboard.TargetName=\"Element\" \n";
    lstr += "            Storyboard.TargetProperty=\"StrokeDashOffset\" \n";
    lstr += "            From=\"1500\" To=\"0\" \n";
    lstr += "            Duration=\"0:5:0\" />\n";
    lstr += "        </Storyboard>\n";
    lstr += "       </vsm:VisualState>\n";
    lstr += "      </vsm:VisualStateGroup>\n";
    lstr += "     </vsm:VisualStateManager.VisualStateGroups>\n";

    lstr += "     <Path x:Name=\"Element\" \n";
    lstr += "        StrokeDashArray=\"MyType\" \n";
    lstr += "        StrokeDashOffset=\"0\" \n";
    lstr += "        Stroke=\"MyColor\" \n";
    lstr += "        StrokeThickness=\"MyThickness\" \n";
    lstr += "        StrokeDashCap=\"Round\" \n";
    lstr += "        StrokeEndLineCap=\"Flat\"  \n";
    lstr += "        StrokeStartLineCap=\"Flat\"/>\n";
    lstr += "    </Grid>\n";

    lstr += "   </ControlTemplate>\n";

    return lstr;
   }
  }
  #endregion
0 Kudos