Select to view content in your preferred language

Sublayer List Help

976
2
10-09-2010 09:31 AM
JMcNeil
Deactivated User
Hello Silverlight Users,

I need some help....I have a problem that just came up and I can't figure out how to fix it and the application is already deployed.  I'm using the sublayer list example from the SDK.  The only thing I did was I add some scrollviewers because I have a lot of layers. 

Here's the problem....everything is fine until the users try to turn off a lot of layers (maybe they just want to display one or two.  When the do this this and then use the verticle scrollviewer it randomly checks off layers but the layers don't draw.  So the check box randomly gets checked on a few random layers but the layers don't really  become visible.  It is like the check box on/off get possessed from using the scrollviewer. 

EVERYTIME I scroll up and down something a new check box is checked or uncheck.  At first I thought it was like miss mouse click but it is not.


Any help would be greatly appreciated.

Here's my XAML Code


       <ListBox Margin="0,5,0,0" ItemsSource="{Binding ElementName=Map, Path=Layers.[DRECP].Layers}"  BorderThickness="0" BorderBrush="{x:Null}" Width="320" Height="280" ScrollViewer.VerticalScrollBarVisibility="Auto">
                                        <ListBox.Background>
                                            <ImageBrush Stretch="Fill"/>

                                        </ListBox.Background>

                                           
                                               <ListBox.ItemTemplate>
                                            <DataTemplate>
                                                <CheckBox Margin="2" Name="DRECP" Content="{Binding Name}" IsChecked="{Binding DefaultVisibility}" 
                                                        Tag="{Binding ID}" ClickMode="Press" Click="CheckBox_Click" />


                                            </DataTemplate>
                                        </ListBox.ItemTemplate>
                                        


                                    </ListBox>



                        

My  code Behind


  #region Layer List


private void CheckBox_Click(object sender, RoutedEventArgs e)
        {
            CheckBox tickedCheckBox = sender as CheckBox;

            string serviceName = tickedCheckBox.Name;
            bool visible = (bool)tickedCheckBox.IsChecked;

            int layerIndex = (int)tickedCheckBox.Tag;

            ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer dynamicServiceLayer = Map.Layers[serviceName] as
                ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer;

            List<int> visibleLayerList =
                dynamicServiceLayer.VisibleLayers != null
                ? dynamicServiceLayer.VisibleLayers.ToList() : new List<int>();

            if (visible)
            {
                if (!visibleLayerList.Contains(layerIndex))
                    visibleLayerList.Add(layerIndex);
            }
            else
            {
                if (visibleLayerList.Contains(layerIndex))
                    visibleLayerList.Remove(layerIndex);
            }

            dynamicServiceLayer.VisibleLayers = visibleLayerList.ToArray();
        }



         private void ArcGISDynamicMapServiceLayer_Initialized(object sender, EventArgs e)
        {
            ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer dynamicServiceLayer =
                sender as ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer;
            if (dynamicServiceLayer.VisibleLayers == null)
                dynamicServiceLayer.VisibleLayers = GetDefaultVisibleLayers(dynamicServiceLayer);
        }

        private int[] GetDefaultVisibleLayers(ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer dynamicService)
        {
            List<int> visibleLayerIDList = new List<int>();

            ESRI.ArcGIS.Client.LayerInfo[] layerInfoArray = dynamicService.Layers;

            for (int index = 0; index < layerInfoArray.Length; index++)
            {
                if (layerInfoArray[index].DefaultVisibility)
                    visibleLayerIDList.Add(index);
            }
            return visibleLayerIDList.ToArray();
        }        #endregion
0 Kudos
2 Replies
JMcNeil
Deactivated User
I know it is a lot to ask but would someone please take a look at my code and maybe quickly throw it in a application.  There is no reason why I should have this problem and I just can't figure it out.  My boss and endusers are on top of me and at this point I have exhusted all my ideas.

Thanks a bunch.
J
0 Kudos
JMcNeil
Deactivated User
SWEEEET!!!!!!!!!!!!!!

I think I just solved it.  The problem doesn't exist when there are less than like 15 layers but once the list gets over 30 it begins to happen.  I don't know why I did not try this earlier.  All I did to solve the problem was move the scrollviewer outside of the list.



                                    <ScrollViewer Width="320" Height="280" VerticalAlignment="Top" Margin="0,5,0,0" RenderTransformOrigin="0.5,0.5"   >
                                        <Grid >


<ListBox Margin="0,5,0,0" ItemsSource="{Binding ElementName=Map, Path=Layers.[0].Layers}" BorderThickness="0" BorderBrush="{x:Null}" Width="300">
                                                <ListBox.Background>
                                                    <ImageBrush Stretch="Fill"/>

                                                </ListBox.Background>


                                                <ListBox.ItemTemplate>
                                                    <DataTemplate>
                                                        <CheckBox Margin="2" Name="DRECP" Content="{Binding Name}" IsChecked="{Binding DefaultVisibility}" 
                                                        Tag="{Binding ID}" ClickMode="Press" Click="CheckBox_Click" />


                                                    </DataTemplate>
                                                </ListBox.ItemTemplate>



                                            </ListBox>
                                        </Grid>
                                    </ScrollViewer>





I think that did it.  Initial test are looking good.
0 Kudos