Select to view content in your preferred language

2.1 Legend

1328
7
11-17-2010 06:43 AM
DaveOrlando
Frequent Contributor
Great work on the 2.1 Release Candidate.
Absolutely love the legend, but of course I have an issue that I would like some advice on.

A few of my services (orthos) I have turned off at startup, but of course they show up checked due to the binding being set to 'IsInScaleRange', as per the example.

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

I have tried to switch the binding to IsVisible, which looks like it works because it checks the correct services, but the functionality of the check box breaks.

any suggestions?
0 Kudos
7 Replies
DominiqueBroux
Esri Frequent Contributor
In the sample, the binding is this one:
 
 <CheckBox Content="{Binding Label}"
                  IsChecked="{Binding IsEnabled, Mode=TwoWay}"
                  IsEnabled="{Binding IsInScaleRange}" >


'IsInScaleRange' is binded to 'IsEnabled' in order to dim the checkbox. It doesn't affect the check status.

You could as well define:
 
 <CheckBox Content="{Binding Label}"
                  IsChecked="{Binding IsEnabled, Mode=TwoWay}" >

The only difference is that the checkbox will not be grayed when the layer is out of scale.
0 Kudos
DaveOrlando
Frequent Contributor
Thanks for the response Dom,

Maybe I should just ask the question...

Is it possible to leave the checkbox unchecked if my service's visibility is set to false by default?
(and maintain the check box's functionality)
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I would need more info on what you want to do.

Let's take an example with the sample you pointed out.
The attached screen shot shows the result when the service's visibility is set to false (layer.Visible = false) and when only 2 of 3 sublayers are set to visible (layer.VisibleLayers= {2, 3} ).

The checkbox of the service is unchecked (seems what you want) but the checkboxes of the sublayers are depending on the VisibleLayers property  (despite the fact that none of these sublayers be visible because the layer itself is checked off).
If now you checked on the layer visibility, the sublayers 2 and 3 will be displayed (but the status of the sublayers checkboxes will not change).
I am guessing that you need to show if a sublayer is currently viisble or not. For that, you can use the 'IsVisible' property (which is taking of care of the visibility of all ascendants and is also taking care of the scale).
But this property is Read-Only, so populate the checkbox with this property is probably not the best use case.
0 Kudos
DaveOrlando
Frequent Contributor
Hi again,

The sublayers are fine, I am just having trouble with the actual services.

I do not get the same results. All my boxes are 'checked'.

Where are you setting the layer's visiblility? I am setting it right in the xaml (Visible="False") not in code-behind. Do you still get the results you described when the vis is set in xaml?
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Oh yeah.

There was a bug which is fixed with the version I am using (and will be fixed in final). When layer visibilities are changed by API, the GUI was not updated.

I forgot it. Sorry about that.
0 Kudos
RyanCoodey
Frequent Contributor
Sounds like it is fixed in the final, which is good... For the time being I fixed this by doing the following in the Loaded event:

            foreach (LayerItemViewModel layerItem in Legend.LayerItems)
                layerItem.IsEnabled = layerItem.IsVisible;


I am binding to the IsEnabled like in the sample... but set their initial value which doesn't seem set using the above code.
0 Kudos
DaveOrlando
Frequent Contributor
Thanks Dom, I can see what is happening now. For example, when I start my editor (which adds a graphic layer) the legend checkboxes change to reflect the proper visibilities.

looking forward to 2.1 final 😉



Thanks for the snippet Ryan, I ended up using something different but thanks.
0 Kudos