Help with BasemapItemTemplate Table of Contents

265
2
04-23-2020 12:38 PM
JoeHershman
MVP Regular Contributor

In the new version of the TableOfContents it no longer uses the common LiyerList.  This approach the basemap behaved similar to the OperationalLayer and both would have a check box.  With the new design there is a TocItem.Content which differs for Basemap layers.

This uses the BasemapItemTemplate and I see where this could be adjusted.  Adding a check box isn't an issue but the issue is how would I tie the checkbox to the actual BaseLayer (we can assume there is only one).  I tried this:

<DataTemplate>
	<Grid Margin="0,2">
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="Auto" />
			<ColumnDefinition Width="*" />
		</Grid.ColumnDefinitions>
		<CheckBox IsChecked="{Binding Content.BaseLayers[0].IsVisible, Mode=TwoWay}">
			<!--<CheckBox.Style>
				<Style TargetType="CheckBox">
					<Style.Triggers>
						<DataTrigger Binding="{Binding Content.CanChangeVisibility, Mode=OneTime}" Value="False">
							<Setter Property="Visibility" Value="Collapsed" />
						</DataTrigger>
					</Style.Triggers>
				</Style>
			</CheckBox.Style>-->
		</CheckBox>
		<TextBlock Text="{Binding Content.Name, Mode=OneWay}" Grid.Column="1" VerticalAlignment="Center" />
	</Grid>
</DataTemplate>

I have tried to find something showing how to bind to a specific item in the ItemsSource without any luck

Thoughts?

Morten Nielsen

0 Kudos
2 Replies
dotMorten_esri
Esri Frequent Contributor

I'd assume that works. Did you check the output window for any binding errors? That should give you a hint why the binding isn't working.

we can assume there is only one

That is definitely a big assumption. A lot of the basemaps also have reference layers (ie labels).

Also check the sample which uses the context menu to completely replace the basemap.

arcgis-toolkit-dotnet/TableOfContentsSample.xaml.cs at master · Esri/arcgis-toolkit-dotnet · GitHub 
That might give you additional ideas how to handle this (like setting the basemap to null or empty).

Generally the basemap was designed to be operated on as a whole. I guess it would have been useful to also have  a Visibility property on the basemap as a whole.

0 Kudos
JoeHershman
MVP Regular Contributor

I guess should have been:

I can assume there is only one (because I know how the map is loaded in this application)

My attempt did not work, using the Binding to BaseLayers[0].  I'll look at the sample, for now I hold the BaseLayer and just turn on off in event handlers, which works.  I would like to do in the template though.

private void ToggleButton_OnChecked(object sender, RoutedEventArgs e)
{
	_baseLayer.IsVisible = true;
}

private void ToggleButton_OnUnchecked(object sender, RoutedEventArgs e)
{
	_baseLayer.IsVisible = false;
}

Thanks

-Joe

0 Kudos