Select to view content in your preferred language

.... about UniqueValueRenderer

836
4
03-29-2011 07:02 AM
MarcoRosa
Emerging Contributor
Hi , i would like to set UniqueValueRenderer by code , to create a thematic map on a layer dinamically.
I tried to do this .... non errors but no result on map.
Please help me to find be the mistake 🙂
thank u GP

********************

xaml code

<UserControl.Resources>

        <esri:SimpleFillSymbol x:Key="MyYellowFillSymbol" Fill="#44FFFF00" BorderBrush="Transparent" BorderThickness="2" />
        <esri:SimpleFillSymbol x:Key="MyRedFillSymbol" Fill="#44FF0000" BorderBrush="Transparent" BorderThickness="2" />
  
</UserControl.Resources>


behind code:


UniqueValueRenderer uvl = new UniqueValueRenderer();
uvl.Attribute = "STATE_NAME";

UniqueValueInfo uvi = new UniqueValueInfo();
uvi.Value = "Arizona";
uvi.Symbol = LayoutRoot.Resources["MyRedFillSymbol"] as FillSymbol;
uvl.Infos.Add(uvi);
                   
FeatureLayer f = new FeatureLayer();
f.ID = "MyFeatureLayerUnique";
f.Url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5";
f.Where = "STATE_NAME = 'Arizona'";
f.Renderer = uvl as UniqueValueRenderer; 
MyMap.Layers.Add(f);
0 Kudos
4 Replies
DominiqueBroux
Esri Frequent Contributor
uvi.Symbol = LayoutRoot.Resources["MyRedFillSymbol"] as FillSymbol;

What is 'LayoutRoot'? is it the UserControl where the symbols resources are defined?
0 Kudos
MarcoRosa
Emerging Contributor
hi dominique , the answer is yes
0 Kudos
JenniferNery
Esri Regular Contributor
I think what Dominique is trying to say is after this line does
LayoutRoot.Resources["MyRedFillSymbol"] as FillSymbol;

return a symbol or null?

Most likely, you have Grid x:Name="LayoutRoot" and in your code-snippet, the symbol resources are defined higher at the UserControl level, which means you might need to do the following instead:
uvi.Symbol = this.Resources["MyRedFillSymbol"] as FillSymbol; 
0 Kudos
MarcoRosa
Emerging Contributor
it's true .... that was the error thanks jennifer.
See u 🙂
0 Kudos