Select to view content in your preferred language

Hi I want to show just one Template out of a template group in a service in code

1198
4
05-23-2011 08:13 AM
MuralidharMoka
Emerging Contributor
Hi I have been trying to show only on template from the service.

I am trying to show just one template from my service.The template will just draws a polygon.
So I was trying to use the ESRI Sample code which is the following,

http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ToolkitTemplatePicker

This example gets all the templates in each of the service.

My requirement is to get on template from the whole template group in the service.
I wanted to do thorough this in the Template_loaded code.

I though I can acess the Template group and then filter it by the names of the template,
but I dont know how to acess the template group on the code behind.

This is what I tried.
        private void MyTemplatePicker_Loaded(object sender, RoutedEventArgs e)
        {
            string[] myLayerIDs = { "Evacuation Perimeter" };
            MyTemplatePicker.LayerIDs = myLayerIDs;
            IEnumerable<TemplateGroup> temp = MyTemplatePicker.TemplateGroups;
        }

I just used only one service "Evacuation Perimeter" this has two templates ,which can draw Yellow and green Polygons.

I just wanted to get only one template say just the Yellow , wanted to do from code behind.
can any one help me. Just give me an idea.

At this line I dont get the template group.

////My XAML looks like this with template style code. In the XMAL when I look at the the template picker style code.
I see this line  ItemsSource="{TemplateBinding TemplateGroups}"
Where is the TemplateGroups property getting from? How can I acess that in code.
Even if I acess I do not know how to proceed until I filter a template.


<toolkit:TemplatePicker x:Name="MyTemplatePicker"
                                    Map="{Binding ElementName=MyMap, Mode=OneWay}"
                                    ShowAttributesOnAdd="True"
                                    Loaded="MyTemplatePicker_Loaded"
                                  >
                <toolkit:TemplatePicker.Template>
                    <ControlTemplate  TargetType="toolkit:TemplatePicker">
                        <ItemsControl ItemsSource="{TemplateBinding TemplateGroups}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Vertical">
                                        <TextBlock Text="{Binding Name}" Foreground="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}" />
                                        <ItemsControl ItemsSource="{Binding Templates}">
                                            <ItemsControl.ItemsPanel>
                                                <ItemsPanelTemplate>
                                                    <StackPanel Orientation="Horizontal" />
                                                </ItemsPanelTemplate>
                                            </ItemsControl.ItemsPanel>
                                            <ItemsControl.ItemTemplate>
                                                <DataTemplate>
                                                    <Grid>
                                                        <Button HorizontalContentAlignment="Center" Margin="2" Command="{Binding Editor.Add}" CommandParameter="{Binding TypeID}" ToolTipService.ToolTip="{Binding Name}">
                                                            <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Vertical">
                                                                <esriPrimitives:SymbolDisplay Height="25" Width="30" Symbol="{Binding Symbol}" />
                                                            </StackPanel>
                                                        </Button>
                                                    </Grid>
                                                </DataTemplate>
                                            </ItemsControl.ItemTemplate>
                                        </ItemsControl>
                                    </StackPanel>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </ControlTemplate>
                </toolkit:TemplatePicker.Template>
               
            </toolkit:TemplatePicker>
0 Kudos
4 Replies
MuralidharMoka
Emerging Contributor
If My question was confusing.

From the Template Picker Sample

http://help.arcgis.com/en/webapi/sil...TemplatePicker


I  wanted to show just the Template which draws Yellow Polygons.
How can we do this from code behind. That was my question in short.

Muralidhar Moka
0 Kudos
JenniferNery
Esri Regular Contributor
You can exclude symbol templates from other layers, by setting TemplatePicker.LayerIDs property. http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client.Toolkit~ESRI.ArcGIS.Client.To...

In your XAML, add this code:
LayerIDs="Evacuation Perimeter"


If you want to further limit the symbol templates to specific symbols, you can create a two-way binding on TemplatePicker.Templates and your own class that implements INotifyPropertyChanged.

public MainPage()
{
 InitializeComponent();

 MyTemplates myTemplates = new MyTemplates();
 Binding b = new Binding("Templates");
 b.Source = myTemplates;
 b.Mode = BindingMode.TwoWay;
 MyTemplatePicker.SetBinding(TemplatePicker.TemplatesProperty, b);
}


public class MyTemplates : INotifyPropertyChanged
{
 public MyTemplates() { }
 private IEnumerable<SymbolTemplate> templates;
 public IEnumerable<SymbolTemplate> Templates 
 {
  get { return templates; }
  set
  {
   if (templates != value && value != null)
   {    
    SymbolTemplate st = null;
    foreach (var t in value)
    {
     if (t.Name == "Mandatory Evacuation")
     {
      st = t;
      break;
     }
    }
    if(st != null)    
    {
     templates = new List<SymbolTemplate>() { st };
     if (PropertyChanged != null)
      PropertyChanged(this, new PropertyChangedEventArgs("Templates")); 
    }
   }
  }
 }
 public event PropertyChangedEventHandler PropertyChanged;
}


Another way is to use Editor.Add instead of TemplatePicker and for Button.Content, you can consider using ESRI.ArcGIS.Client.Toolkit.Primitives.SymbolDisplay.
0 Kudos
MuralidharMoka
Emerging Contributor
Thank you very much.

I did not know that editor can do this.
Would you pls point me to any editor example,
I do not know how to use it.

if not if f = MyMap.Layers["FeatLayer"] as FeatureLayer;

how do I proceed next with if say I have MyEditor as the instance.

would you pls write some sample code for me to start.

Thanks for the great help

Thanks
Muralidhar Moka
0 Kudos
JenniferNery
Esri Regular Contributor
0 Kudos