<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Width="200" Background="Transparent" Margin="10,10,10,10"> <Grid> <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" Background="Transparent" Margin="10,0,0,0"> <CheckBox x:Name="WeatherLayer" IsChecked="{Binding Visible, Mode=TwoWay}" Foreground="White" Click="WmsLayer_Initialized" /> <!--Opacity slider--> <Slider Margin="-5,0,0,0" Minimum="0" Maximum="1" Width="50" Value="{Binding Opacity, Mode=TwoWay}" Height="18" /> <TextBlock Text=" National Weather" Foreground="White"/> </StackPanel> </Grid> </StackPanel>
String[] VisibleWmsLayers = { "nexrad-n0r-900913-m05m" }; nexradWmsLayer.Layers = VisibleWmsLayers; nexradWmsLayer.Opacity = Slider.?
<CheckBox x:Name="WeatherLayer" IsChecked="{Binding Visible, Mode=TwoWay}" Foreground="White" Click="WmsLayer_Initialized" />
My method WMSLayer_Initialized turns the weather layer on and off
<Slider Margin="-5,0,0,0" Minimum="0" Maximum="1" Width="50" Value="{Binding Opacity, Mode=TwoWay}" Height="18" />
nexradWmsLayer.Opacity = Slider.?
<esri:WmsLayer ID="Nexrad" Opacity="0.5"
SkipGetCapabilities="True" Initialized="WmsLayer_Initialized" Visible="False" />
Now I want to add the Opacity Slider but it looks like you can't mix and match the bindings to what is going on in the code behind. Is that true? I am essentially calliing the same method twice in my xaml too, does that matter?
Everything works except for the slider part of it. My inquiring mind wants to know...
MySlider.SetBinding(Slider.ValueProperty, new Binding("Opacity") { Mode = BindingMode.TwoWay, Source = nexradWmsLayer });
private void WmsLayer_Initialized(object sender, EventArgs e) { try { WmsLayer nexradWmsLayer = null; nexradWmsLayer = (WmsLayer)Map.Layers["Nexrad"]; String url = Configuration.getAGSAppSetting("weather"); nexradWmsLayer.Url = url.ToString(); String version = Configuration.getAGSAppSetting("weather_version"); nexradWmsLayer.Version = version.ToString(); //ToDo...Add layer list to config file... String[] VisibleWmsLayers = { "nexrad-n0r-900913-m05m" }; nexradWmsLayer.Layers = VisibleWmsLayers; //this.WeatherSlider.SetBinding(Slider.ValueProperty, new Binding("Opacity"){ Mode = BindingMode.TwoWay, Source = nexradWmsLayer }); bool visible = nexradWmsLayer.Visible; if (this.WeatherLayer.IsChecked == true) { nexradWmsLayer.Visible = true; } if (this.WeatherLayer.IsChecked == false) { nexradWmsLayer.Visible = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//this.WeatherSlider.SetBinding(Slider.ValueProperty, new Binding("Opacity"){ Mode = BindingMode.TwoWay, Source = nexradWmsLayer });
private void MyMap_Loaded(object sender, System.Windows.RoutedEventArgs e) { var map = sender as ESRI.ArcGIS.Client.Map; String url = Configuration.getAGSAppSetting("weather"); String version = Configuration.getAGSAppSetting("weather_version"); //ToDo...Add layer list to config file... String[] VisibleWmsLayers = { "nexrad-n0r-900913-m05m" }; map.Layers.Add(new WmsLayer() { Url = url, Version = version, Layers = VisibleWmsLayers , ID="Nexrad" }); }