Your code work correctly to reduce opacity for each layer in my application. But, I have other problem, when I unchecked the checkbox, the layer will disappear.
Code creating the same legend control than in the sample you pointed out:public LegendWithTemplates() { InitializeComponent(); LayoutRoot.Children.Add(CreateLegend()); } Legend CreateLegend() { var legend = new Legend { LayerIDs = new[] { "Points of Interest", "United States" }, LayerItemsMode = Legend.Mode.Tree, ShowOnlyVisibleLayers = false, Height = 300, Width = 200, HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(20) }; legend.SetBinding(Legend.MapProperty, new Binding {ElementName = "MyMap"}); legend.Refreshed += Legend_Refreshed; legend.MapLayerTemplate = CreateTemplate(@" <StackPanel Orientation=""Horizontal""> <CheckBox Content=""{Binding Label}"" IsChecked=""{Binding IsEnabled, Mode=TwoWay}"" IsEnabled=""{Binding IsInScaleRange}"" > </CheckBox> <Slider Maximum=""1"" Value=""{Binding Layer.Opacity, Mode=TwoWay}"" Width=""50"" /> </StackPanel>"); legend.LayerTemplate = CreateTemplate(@" <CheckBox Content=""{Binding Label}"" IsChecked=""{Binding IsEnabled, Mode=TwoWay}"" IsEnabled=""{Binding IsInScaleRange}"" > </CheckBox>"); return legend; } static DataTemplate CreateTemplate(string template) { return (DataTemplate)System.Windows.Markup.XamlReader.Load(@<DataTemplate xmlns="http://schemas.microsoft.com/client/2007"">" + template + "</DataTemplate>"); }
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.