DynamicMapServiceLayer added through code not recognized by button.

2128
2
11-25-2014 02:22 PM
ThomasCox
Occasional Contributor

Please bear with the low level this question is probably at. I am new to the Runtime and wpf xaml.  I
believe my question is more wpf/xaml based one. I hope my description that follows is clear enough.

I have developed a prototype app attempting to emulate the mvvm pattern.  Between looking at the
toolkit samples and the regular runtime samples, I have implemented a 'toggle visible layer' method in my MapViewModel.cs that is successfully bound to a button on my MainWindow.xaml.  This button is handling a feature layer that I add to the application through app.xaml.  This is working well. I am able to toggle the layer's visibility through the button.

I want to add another button to handle another layer and leverage the same toggle visible method. I have added the button in MainWindow.xaml and set up the same binding parameters, except of course using the correct layer name. However, the additional layer that I wish to ‘toggle’ is added through code in the MapViewModel as a DynamicMapService Layer from a map package.

The layer I am interested in is successfully added to the map  However, the button that I have added to toggle the visibility for this layer is never enabled. I incorrectly assumed that this button would come to life when the layer is added to the map.  No such luck.

Is it possible to associate a control with command method using a layer that is added through code as the parameter?

What would be the correct approach to handling this situation?

Any insight would be appreciated.

0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor

The availability of a button is depending on the way you implemented the underlying action.

If you affected a command to the button, the avaibility is defined by the CanExecute method of the command, so really depending on how you implemented it.

I suggest you look at the 'LayerList' sample which demonstrates how to display a list of layers with the possibility to turn on/off each layer.

0 Kudos
ThomasCox
Occasional Contributor

Thanks Dominique.  I had not looked at the LayerList Sample.  Your comment about the CanExecute method helped me see the error of my ways.

Thanks again for your response.

0 Kudos