<Windows:HierarchicalDataTemplate x:Key="GroupTemplate" ItemTemplate="{StaticResource LayerTemplate}" ItemsSource="{Binding Path=MapGroups}"> <StackPanel Orientation="Vertical"> <StackPanel Orientation="Horizontal" MouseRightButtonDown="StackPanelMouseRightButtonDown" Margin="10,0,10,0" > <CheckBox IsTabStop="False" IsThreeState="False" IsChecked="{Binding IsVisible, Mode=TwoWay}" Commands:Click.Command="{Binding TreeNodeClickCommand}" Margin="5,0,5,0" Commands:Click.CommandParameter="{Binding ElementName=TreeViewControl, Path=SelectedItem}" Click="CheckBoxClick" VerticalAlignment="Center"/> <TextBlock Text="{Binding Path=Name}" Width="120" Margin="0" VerticalAlignment="Center"/> <Slider Minimum="0" Maximum="1" Width="100" Margin="10,0,10,0" Value="{Binding Opacity, Mode=TwoWay}" Infrastructure:SliderValueChange.Command="{Binding OpacityChangeCommand}"/> </StackPanel> </StackPanel> </Windows:HierarchicalDataTemplate>
<Controls:TreeView x:Name="TreeViewControl" Background="{StaticResource MainPageBackgroundBrush}" ItemTemplate="{StaticResource GroupTemplate}" ItemsSource="{Binding MapServiceLayers, Mode=TwoWay}" FlowDirection="{Binding FlowDirection, Mode=TwoWay}" />
Many thanks for the reply Joe. However I'm still lost. How is this implemented? When a users enters a URL how would and it's initialized and added to the map in the code behind, how is this then passed to the various elements in the XAML? Really struglling with getting the concept of linking elements from the C# code behind and the XAML elements.
Any further help would be very much appreciated.
string url = theUserUrl; ArcGISDynamicMapServiceLayer layer = new ArcGISDynamicMapServiceLayer {Url = the UserUrl }; // this might be ArcGISTiledMapServiceLayer depending on the service type MyMap.Layers.Add(layer);
<esri:Legend Map="{Binding ElementName=MyMap}"
Many thanks Joe for the tips, code and advice. I really appreciate it. I thought by picking a "project" I would grasp the concepts quicker but this is proving elusive with silverlight for me. Any way will keep at it.
Just so we are on the same page, and for the benefits of other who may or may not be in the same predicament as me this is what I am looking to do
1. User enters a URL to a Map service, (see link above) - Currently this sample works for Tiled services - Looking to eventually extend this so service type doesn't matter.
2. With no map displayed on the map canvas yet, the sub-layers, if any, would be listed - in a folder or tree fashion.
3. User selects a sub-layer, and can at this point add it to or display it on the map canvas. And at this point it can be added to the legend control.
The attached does pretty much what it seems you want as far as building the tree, there is too much there to try and just put code snippets. The TocViewModel contains code that builds a MapServiceLayer objects collection, Each MapServiceLayer represents a service and the layers/sublayers are then in its ObservableCollection<MapGroup>. I broke it out into two object type a MapGroup an MapServiceLayer, a MapServiceLayer is a MapGroup but defines the actual service. A MapGroup has its own MapGroup collection which has 0 or more elements. This works on the layers in an existing map but the principle would be the same. I bound the ObservableCollection<MapServiceLayer> to a treeview using HierarchicalDataTemplate like in my earlier post.