Select to view content in your preferred language

Migrating Toolbars to 2.3

1689
3
01-03-2012 01:22 PM
MarcusHarner
Regular Contributor
I have several web apps built with 2.2 that use the Toolbar class.  As noted in the API Reference and the ???What's new in 2.3???, this class and related classes have been deprecated.  I would like to move to 2.3 to use the client side spatial operations, which sound very nifty, but need to replace the references for the Toolbar class as suggested by Visual Studio ??????'Please use a Panel or other container control, such as a StackPanel or Grid.'????????? 
The examples in the Sample library still use the Toolbar class.
Is there a simple example of a best/easiest practice to replace the Toolbar class with Panels or a grid using the 2.3 API?
Thanks much.
0 Kudos
3 Replies
JenniferNery
Esri Regular Contributor
You can make the following changes to the old SDK sample: http://help.arcgis.com/en/webapi/silverlight/2.2/samples/start.htm#ToolBarWidget

Use Image.Tag and MouseLeftButtonDown. Declare _previousExtentImage and _nextExtentImage in XAML instead.
    <StackPanel Orientation="Horizontal">
     <Image Source="/Assets/images/i_zoomin.png" Stretch="UniformToFill" Margin="5" Tag="zoomin" MouseLeftButtonDown="Image_MouseLeftButtonDown"/>    
     <Image Source="/Assets/images/i_zoomout.png" Stretch="UniformToFill" Margin="5" Tag="zoomout" MouseLeftButtonDown="Image_MouseLeftButtonDown"/>
     <Image Source="/Assets/images/i_pan.png" Stretch="UniformToFill" Margin="5" Tag="pan"  MouseLeftButtonDown="Image_MouseLeftButtonDown"/>
     <Image x:Name="_previousExtentImage" Source="/Assets/images/i_previous.png" IsHitTestVisible="False" Opacity="0.3" Stretch="UniformToFill" Margin="5" Tag="previousextent" MouseLeftButtonDown="Image_MouseLeftButtonDown"/>
     <Image x:Name="_nextExtentImage" Source="/Assets/images/i_next.png" IsHitTestVisible="False" Opacity="0.3" Stretch="UniformToFill" Margin="5" Tag="nextextent" MouseLeftButtonDown="Image_MouseLeftButtonDown"/>
     <Image Source="/Assets/images/i_globe.png" Stretch="UniformToFill" Margin="5" Tag="fullextent" MouseLeftButtonDown="Image_MouseLeftButtonDown"/>
     <Image Source="/Assets/images/i_widget.png" Stretch="UniformToFill" Margin="5" Tag="fullscreen" MouseLeftButtonDown="Image_MouseLeftButtonDown"/>
    </StackPanel>


private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  {
   _toolMode = (sender as Image).Tag.ToString();
   StatusTextBlock.Text = _toolMode;
   MyDrawObject.IsEnabled = false;
            switch (_toolMode)
            {
                case "zoomin": // ZoomIn Layers
                    MyDrawObject.IsEnabled = true;
                    _toolMode = "zoomin";
                    break;
                case "zoomout": // Zoom Out
     MyDrawObject.IsEnabled = true;
                    _toolMode = "zoomout";
                    break;
                case"pan": // Pan
                    break;
                case "previousextent": // Previous Extent
                    if (_currentExtentIndex != 0)
                    {
                        _currentExtentIndex--;
                        
                        if (_currentExtentIndex == 0)
                        {
                            _previousExtentImage.Opacity = 0.3;
                            _previousExtentImage.IsHitTestVisible = false;
                        }

                        _newExtent = false;

                        MyMap.IsHitTestVisible = false;
                        MyMap.ZoomTo(_extentHistory[_currentExtentIndex]);

                        if (_nextExtentImage.IsHitTestVisible == false)
                        {
                            _nextExtentImage.Opacity = 1;
                            _nextExtentImage.IsHitTestVisible = true;
                        }
                    }
                    break;
                case "nextextent": // Next Extent
                    if (_currentExtentIndex < _extentHistory.Count - 1)
                    {
                        _currentExtentIndex++;

                        if (_currentExtentIndex == (_extentHistory.Count - 1))
                        {
                            _nextExtentImage.Opacity = 0.3;
                            _nextExtentImage.IsHitTestVisible = false;
                        }

                        _newExtent = false;

                        MyMap.IsHitTestVisible = false;
                        MyMap.ZoomTo(_extentHistory[_currentExtentIndex]);

                        if (_previousExtentImage.IsHitTestVisible == false)
                        {
                            _previousExtentImage.Opacity = 1;
                            _previousExtentImage.IsHitTestVisible = true;
                        }
                    }
                    break;
                case "fullextent": // Full Extent
                    MyMap.ZoomTo(MyMap.Layers.GetFullExtent());
                    break;
                case "fullscreen": // Full Screen
                    Application.Current.Host.Content.IsFullScreen = !Application.Current.Host.Content.IsFullScreen;
                    break;
            }
  }
0 Kudos
dotMorten_esri
Esri Notable Contributor
FYI the Toolbar is still there and can be used. It has simply been marked as deprecated, and will at some point go away (most likely and no sooner than v3.0).

But Jennifer's suggestion is correct. Simply use the built-in controls that Silverlight provides. Ie. basically Buttons in a StackPanel (this is really all the Toolbar is, but it doesn't support proper design time support).
0 Kudos
MarcusHarner
Regular Contributor
Y'all are wonderful and this is exactly what I was hoping for.  Just the little snippets of code and the examples save me hours of frustration.  Thank you so very much!
0 Kudos