AnsweredAssumed Answered

Unable to show FeatureLayer using code behind

Question asked by HuyHo on May 5, 2016
Latest reply on May 13, 2016 by MBranscomb-esristaff

We are having trouble loading FeatureLayers from the code behind.  We based our example on the FeatureLayerHitTesting sample using the following feature layer as a guide:

If we added the feature layer using XAML, the features would show up as expected:


        <esri:FeatureLayer ID="FeatureLayer">
              <esri:SimpleMarkerSymbol Color="LightBlue" Style="Circle" Size="12">
                  <esri:SimpleLineSymbol Color="Blue" Width="2" Style="Solid" />
            <esri:ServiceFeatureTable ServiceUri=""
                            Where="pop2000 > 200000" OutFields="*" />



However, if we add the layer using code-behind, the layer would not display.


 async void MyMapView_Loaded(object sender, RoutedEventArgs e)
      Esri.ArcGISRuntime.Layers.FeatureLayer layer = new Esri.ArcGISRuntime.Layers.FeatureLayer();

      ServiceFeatureTable serviceTable = await ServiceFeatureTable.OpenAsync(
        new Uri(""));
      serviceTable.Where = "pop2000 > 200000";

      SimpleMarkerSymbol symbol = new SimpleMarkerSymbol
        Color = Colors.Orange,
        Style = SimpleMarkerStyle.Circle,
        Size = 12,
        Outline = new SimpleLineSymbol
          Color = Colors.Red,
          Width = 2,
          Style = SimpleLineStyle.Solid
      SimpleRenderer renderer = new SimpleRenderer();
      renderer.Symbol = symbol;

      layer.Renderer = renderer;
      layer.FeatureTable = serviceTable;



But interestingly enough, we we try to added the same feature layer in both XAML and code behind, the code-behind layer would show up, but with a wrong projection.



What am I missing here?