ArcGIS Runtime SDK for WPF - Library Reference
AddBookmark Method
See Also  Example
ESRI.ArcGIS.Client.Toolkit Namespace > Bookmark Class : AddBookmark Method

name
Display name (aka. named Map.Extent or bookmark).
extent
The Map.Extent of the bookmark.
Adds a named Map.Extent (aka. a bookmark) into the DataGrid sub-component of the Bookmark Control.

Syntax

Visual Basic (Declaration) 
Public Sub AddBookmark( _
   ByVal name As String, _
   ByVal extent As Envelope _
) 
C# 
public void AddBookmark( 
   string name,
   Envelope extent
)

Remarks

The AddBookmark Method adds a named Map.Extent (aka. a bookmark) into the ObservableCollection(Of Bookmark.MapBookmark) object. The ObservableCollection(Of Bookmark.MapBookmark) object is internally bound to the DataGrid sub-component in the Bookmark Control. Use the Bookmark.Bookmarks Property to obtain the ObservableCollection(Of Bookmark.MapBookmark) object.

There are two input parameters for the AddBookmark Method: name and extent.The name is the human readable string that defines a geographic extent on the Map. The extent is the Map.Extent that corresponds to item name in the ObservableCollection.

The functionality of the AddBookmark Method is comparable to when a user of a client application types a string into the Textbox sub-component of the Bookmark Control and clicks the + button, causing the named Map.Extent (aka. a bookmark) to appear in the DataGrid. It should be noted that the AddBookmark Method IS NOT the Event for the + button of the Bookmark Control. To change the core behavior of any of the sub-components and their appearance of the Bookmark Control (including the + button), developers must modify the Control Template in XAML and the associated code-behind file. The easiest way to modify the UI sub-components is using Microsoft Expression Blend. Then developers can delete/modify existing or add new sub-components in Visual Studio to create a truly customized experience. A general approach to customizing a Control Template is discussed in the ESRI blog entitled: Use control templates to customize the look and feel of ArcGIS controls. An example of modifying the Control Template of the Bookmark control to provide an alternate set of functionality that automatically populates several named Map.Extent (aka. a bookmark) values via the AddBookmark Method is provided in the code example section of this document.

Parameters

name
Display name (aka. named Map.Extent or bookmark).
extent
The Map.Extent of the bookmark.

Example

How to use:

This example code shows disabling some of the features of the Bookmark Control to create a kiosk type of application. Users are not allowed to make any editable changes to the Bookmark Control. To use: Click the various preset bookmarks to see the Four Corners area of the United States.

The following screen shot corresponds to the code example in this page.

Example of overriding the default behavior of the Bookmark Control to auto-populate several bookmarks via the AddBookmark Method.

XAMLCopy Code
<Grid x:Name="LayoutRoot" Background="White">
  
  <!-- 
  Use the Resources section to hold a Style for setting the appearance and behavior of the Bookmark Control. 
  Don't forget to add following XAML Namespace definitions to the correct location in your code:
  xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" 
  xmlns:esri="http://schemas.esri.com/arcgis/client/2009" 
  -->
  <Grid.Resources>
  
    <!--
    The majority of the XAML that defines the ControlTemplate for the Bookmark Control was obtained
    by using Microsoft Blend. See the blog post entitled: 'Use control templates to customize the 
    look and feel of ArcGIS controls' at the following Url for general How-To background:
    http://blogs.esri.com/Dev/blogs/silverlightwpf/archive/2010/05/20/Use-control-templates-to-customize-the-look-and-feel-of-ArcGIS-controls.aspx
    -->
    <Style x:Key="BookmarkStyle1" TargetType="esri:Bookmark">
      <Setter Property="MaxHeight" Value="200"/>
      <Setter Property="Width" Value="120"/>
      <Setter Property="Background" Value="#99000000"/>
    
      <!-- The Title.Value was modified. -->
      <Setter Property="Title" Value="Four Corners Kiosk"/>
      
      <Setter Property="BorderThickness" Value="1"/>
      <Setter Property="BorderBrush" Value="White"/>
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="esri:Bookmark">
            <Grid Background="Yellow">
              <Grid.RowDefinitions>
                <RowDefinition Height="25"/>
                  
                <!-- Changed the Height for better visual appeal. -->
                <RowDefinition Height="1"/>
                                 
                <RowDefinition Height="*"/>
                <RowDefinition Height="25"/>
              </Grid.RowDefinitions>
              <Border BorderBrush="{TemplateBinding BorderBrush}" 
                      BorderThickness="{TemplateBinding BorderThickness}" 
                      Background="{TemplateBinding Background}" 
                      CornerRadius="5" 
                      Grid.RowSpan="4"/>
              <TextBlock Foreground="Black" FontWeight="Bold" FontSize="12" 
                         FontFamily="Verdana" Margin="5,5,5,0" 
                         Grid.Row="0" Text="{TemplateBinding Title}"/>
                 
              <!-- Comment out the entire section that allows users to add bookmarks. Since 
              this is a Kiosk Application, we do not want users to make any changes.
              -->
              <!--
              <Grid Margin="5,0,5,0" Grid.Row="1">
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="*"/>
                  <ColumnDefinition Width="30"/>
                </Grid.ColumnDefinitions>
                <TextBox x:Name="AddBookmarkName" Grid.Column="0" Width="200"/>
                <Button x:Name="AddBookmark" Content="+" Grid.Column="1" />
              </Grid>
              -->
                            
              <!-- Add the IsReadOnly Attribute to disable the user from editing the bookmark names. -->
              <sdk:DataGrid x:Name="BookmarkList" AutoGenerateColumns="False" CanUserResizeColumns="False" 
                            CanUserReorderColumns="False" HeadersVisibility="None" Margin="5,0,5,0" 
                            Grid.Row="2" RowHeight="16" RowDetailsVisibilityMode="Collapsed" 
                            TabNavigation="Local" Visibility="Visible" IsReadOnly="True" >
                <sdk:DataGrid.Columns>
                <sdk:DataGridTextColumn Binding="{Binding Name, Mode=TwoWay}" Foreground="Black" 
                                        FontSize="10" FontFamily="Times" Header="Bookmark" 
                                        IsReadOnly="False" Width="{TemplateBinding Width}"/>
                </sdk:DataGrid.Columns>
              </sdk:DataGrid>
              
              <!-- Comment out the entire section that allows users to delete bookmarks. Since 
              this is a Kiosk Application, we do not want users to make any changes.
              -->
              <!--
              <Grid Margin="5,0,5,5" Grid.Row="3">
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="*"/>
                  <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Button x:Name="ClearBookmarks" Content="Clear All" Grid.Column="0"/> 
              </Grid>
              -->
                              
            </Grid>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>
  </Grid.Resources>
  
  <!-- Provide the instructions on how to use the sample code. -->
  <TextBlock Height="70" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="626" 
             TextWrapping="Wrap" Margin="2,9,0,0" 
             Text="This example code shows disabling some of the features of the Bookmark Control to create
                  a kiosk type of application. Users are not allowed to make any editable changes to the Bookmark
                  Control. To use: Click the various preset bookmarks to see the Four Corners area of the 
                  United States." />
  
  <!-- Add a Map Control to the application and define an intial Map.Extent to the Four Corners states. -->
  <esri:Map x:Name="MyMap" Extent="-12948716, 3633316, -11207358, 5196630"
            Background="White" HorizontalAlignment="Left" Margin="12,85,0,0"  
            VerticalAlignment="Top" Height="360" Width="401">
  
    <!-- Add an ArcGISTiledMapServiceLayer for some quick data display. -->
    <esri:ArcGISTiledMapServiceLayer 
          Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
  </esri:Map>
  
  <!--
  Add a Bookmark Control. It is important to provide an x:Name attribute so it can be referenced
  in the code-behind. Define the Style of the Bookmark to use the Control Template that was generated
  in Blend and modified here in Visual Studio. The Map Property uses the default two-way Binding to 
  associate the Bookmark Control with the Map Control. The Loaded Event handler was added so that in
  the code-behind some predefined bookmarks could be added.
  -->
  <esri:Bookmark x:Name="MyBookmarks" Width="200" HorizontalAlignment="Right" VerticalAlignment="Top" 
                 Margin="0,85,12,0" Background="#CC919191" BorderBrush="#FF92a8b3" Foreground="Black"   
                 Style="{StaticResource BookmarkStyle1}"
                 Map="{Binding ElementName=MyMap}" Loaded="MyBookmarks_Loaded"/>
      
</Grid>
C#Copy Code
private void MyBookmarks_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
  // This function clears out any existing bookmarks and added several new ones to provide predefined
  // functionality for zooming around the Four Corners states of the United States.
  
  // Clear out any existing bookmarks. 
  MyBookmarks.ClearBookmarks();
  
  // Add bookmarks for the various areas of the Four Corners region of the United States.
  ESRI.ArcGIS.Client.Geometry.Envelope myExtentTheFourCorners = new ESRI.ArcGIS.Client.Geometry.Envelope(-12948716, 3633316, -11207358, 5196630);
  MyBookmarks.AddBookmark("The Four Corners", myExtentTheFourCorners);
  
  ESRI.ArcGIS.Client.Geometry.Envelope myExtentArizona = new ESRI.ArcGIS.Client.Geometry.Envelope(-12921190, 3642001, -11973117, 4493139);
  MyBookmarks.AddBookmark("Arizona", myExtentArizona);
  
  ESRI.ArcGIS.Client.Geometry.Envelope myExtentColorado = new ESRI.ArcGIS.Client.Geometry.Envelope(-12190630, 4330502, -11325307, 5107351);
  MyBookmarks.AddBookmark("Colorado", myExtentColorado);
  
  ESRI.ArcGIS.Client.Geometry.Envelope myExtentNewMexico = new ESRI.ArcGIS.Client.Geometry.Envelope(-12289052, 3647640, -11371077, 4471758);
  MyBookmarks.AddBookmark("New Mexico", myExtentNewMexico);
  
  ESRI.ArcGIS.Client.Geometry.Envelope myExtentUtah = new ESRI.ArcGIS.Client.Geometry.Envelope(-12850560, 4409389, -11995243, 5177256);
  MyBookmarks.AddBookmark("Utah", myExtentUtah);
 }
VB.NETCopy Code
Private Sub MyBookmarks_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
  
  ' This function clears out any existing bookmarks and added several new ones to provide predefined
  ' functionality for zooming around the Four Corners states of the United States.
  
  ' Clear out any existing bookmarks. 
  MyBookmarks.ClearBookmarks()
  
  ' Add bookmarks for the various areas of the Four Corners region of the United States.
  Dim myExtentTheFourCorners As New ESRI.ArcGIS.Client.Geometry.Envelope(-12948716, 3633316, -11207358, 5196630)
  MyBookmarks.AddBookmark("The Four Corners", myExtentTheFourCorners)
  
  Dim myExtentArizona As New ESRI.ArcGIS.Client.Geometry.Envelope(-12921190, 3642001, -11973117, 4493139)
  MyBookmarks.AddBookmark("Arizona", myExtentArizona)
  
  Dim myExtentColorado As New ESRI.ArcGIS.Client.Geometry.Envelope(-12190630, 4330502, -11325307, 5107351)
  MyBookmarks.AddBookmark("Colorado", myExtentColorado)
  
  Dim myExtentNewMexico As New ESRI.ArcGIS.Client.Geometry.Envelope(-12289052, 3647640, -11371077, 4471758)
  MyBookmarks.AddBookmark("New Mexico", myExtentNewMexico)
  
  Dim myExtentUtah As New ESRI.ArcGIS.Client.Geometry.Envelope(-12850560, 4409389, -11995243, 5177256)
  MyBookmarks.AddBookmark("Utah", myExtentUtah)
  
End Sub

Requirements

Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7, Windows 8

See Also

© ESRI, Inc. All Rights Reserved.