AnsweredAssumed Answered

Error-Object already owned for LayerCollection

Question asked by Prashant.Kirpan on Sep 10, 2019
Latest reply on Sep 18, 2019 by Prashant.Kirpan

Hi All,

 

I am using WPF 100.5 runtime API with MVVM framework. I have integrated toolkit:LayerLegend control in separate user control which has his own view model.

 

I am passing Map.Operationlayers from MainMapVM to LegendVM and binding to public Layercollection property in usercontrol. This approach is working fine but i want to extract only specific layers and show in legend - this time it fails and throwing 'Object already Owned exception - from ARCGIS Runtime'

 

My sample code.

 

1MapControlViewModel 

 

public class MapControlViewModel : ViewModelBase
{

   public LayerListControlViewModel LayerlistControlVM { get; set; } = new LayerListControlViewModel();

   ..

   public void click()
      {

         //Passing operation layers to legend user control
          LayerlistControlVM.InitializeLayerListControl(Map.OperationalLayers); 
       }

}

----------------------------------------------------------------------------------------------------------------------------------------------------

2. LayerListControlViewModel 

public class LayerListControlViewModel : ViewModelBase
{
    public LayerCollection OperationalLayers { get; set; } = new LayerCollection();

    ..

    

    public void InitializeLayerListControl(LayerCollection layerColl)
         {

             OperationalLayers.Add(layerColl[0]); Exception on this line - 'Object already owned.: Already owned'

             //OperationalLayers = layerColl; Works well

            RaisePropertyChanged(() => OperationalLayers);

 

           }

}

----------------------------------------------------------------------------------------------------------------------------------------------------

2.1 LayerListControl.XAML

 

<ScrollViewer>
     <ItemsControl ItemsSource="{Binding OperationalLayers, Mode=OneWay}" Margin="10" >
          ....

          ....
      </ItemsControl>
</ScrollViewer>

----------------------------------------------------------------------------------------------------------------------------------------------------

I am not sure why i am getting exception while extracting data from Layercollection Object and assign to Public property with same class.

Any help would be appreciated.

 

Regards,

Prashant 

Outcomes