Select to view content in your preferred language

How can I add Tools to the Toolbar??

1278
9
07-26-2010 11:16 AM
JoshV
by
Regular Contributor
Hello All-  I'm using Silverlight 3

I have added the proper XAML and C# to get the basic Toolbar to come into my Silverlight App.  I now want to add the Measure Tool found in the Utility Actions sample at this link.  http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#UtilityActions

Is there a way I can add that tool into the toolbar?  Please let me know.  Thanks
0 Kudos
9 Replies
DominiqueBroux
Esri Frequent Contributor
Except the focus issue which is discuted here http://forums.arcgis.com/threads/9043-Losing-the-focus-of-the-Tool, I think you can just add a new toolbar item containing your button.
0 Kudos
JoshV
by
Regular Contributor
Hi Dominique-

Using this code below (which includes your changes from the other post, thanks) how can I simply add it as another ToolBarItem?  I tried that and an error gets thrown stating that the property content is set more than once.


code for measure tool:
<Button Style="{StaticResource MenuItem}" Click="DisableDrawObject"  HorizontalAlignment="Right"   Foreground="Black"                           
                            Content="Measure"  >
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <esriBehaviors:MeasureAction                                  
                                    AreaUnit="SquareMiles"
                                    DisplayTotals="True"
                                    DistanceUnit="Miles"
                                    MapUnits="DecimalDegrees"
                                    MeasureMode="Polygon"                                   
                                    FillSymbol="{StaticResource DefaultFillSymbol}"
                                    TargetName="MyMap"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>



Code example for Toolbar Items:
<esriToolkit:ToolbarItem Text="Zoom In">
                                <esriToolkit:ToolbarItem.Content>
                                    <Image Source="Assets/images/i_zoomin.png" Stretch="UniformToFill" Margin="5" />
                                </esriToolkit:ToolbarItem.Content>
                            </esriToolkit:ToolbarItem>
                            <esriToolkit:ToolbarItem Text="Zoom Out">
                                <esriToolkit:ToolbarItem.Content>
                                    <Image Source="Assets/images/i_zoomout.png" Stretch="UniformToFill" Margin="5" />
                                </esriToolkit:ToolbarItem.Content>
                            </esriToolkit:ToolbarItem>
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Using this code below (which includes your changes from the other post, thanks) how can I simply add it as another ToolBarItem? I tried that and an error gets thrown stating that the property content is set more than once.


This should work:
<esriToolkit:ToolbarItem Text="Measure">
       <esriToolkit:ToolbarItem.Content>
            <Button Style="{StaticResource MenuItem}" Click="DisableDrawObject"  HorizontalAlignment="Right"   Foreground="Black"  Content="Measure"  >
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <esriBehaviors:MeasureAction                                  
                                    AreaUnit="SquareMiles"
                                    DisplayTotals="True"
                                    DistanceUnit="Miles"
                                    MapUnits="DecimalDegrees"
                                    MeasureMode="Polygon"                                   
                                    FillSymbol="{StaticResource DefaultFillSymbol}"
                                    TargetName="MyMap"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
    </esriToolkit:ToolbarItem.Content>
</esriToolkit:ToolbarItem Text="Measure">
0 Kudos
JoshV
by
Regular Contributor
This should work:
<esriToolkit:ToolbarItem Text="Measure">
       <esriToolkit:ToolbarItem.Content>
            <Button Style="{StaticResource MenuItem}" Click="DisableDrawObject"  HorizontalAlignment="Right"   Foreground="Black"  Content="Measure"  >
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <esriBehaviors:MeasureAction                                  
                                    AreaUnit="SquareMiles"
                                    DisplayTotals="True"
                                    DistanceUnit="Miles"
                                    MapUnits="DecimalDegrees"
                                    MeasureMode="Polygon"                                   
                                    FillSymbol="{StaticResource DefaultFillSymbol}"
                                    TargetName="MyMap"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
    </esriToolkit:ToolbarItem.Content>
</esriToolkit:ToolbarItem Text="Measure">


That worked, thanks Dominique
0 Kudos
JoshV
by
Regular Contributor
This should work:
<esriToolkit:ToolbarItem Text="Measure">
       <esriToolkit:ToolbarItem.Content>
            <Button Style="{StaticResource MenuItem}" Click="DisableDrawObject"  HorizontalAlignment="Right"   Foreground="Black"  Content="Measure"  >
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <esriBehaviors:MeasureAction                                  
                                    AreaUnit="SquareMiles"
                                    DisplayTotals="True"
                                    DistanceUnit="Miles"
                                    MapUnits="DecimalDegrees"
                                    MeasureMode="Polygon"                                   
                                    FillSymbol="{StaticResource DefaultFillSymbol}"
                                    TargetName="MyMap"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
    </esriToolkit:ToolbarItem.Content>
</esriToolkit:ToolbarItem Text="Measure">


Hi Dominique-

Instead of using Text to say Measure how can I use an Image like the other tools in my Toolbar?

Thanks again Dominique
0 Kudos
DominiqueBroux
Esri Frequent Contributor

Instead of using Text to say Measure how can I use an Image like the other tools in my Toolbar?

The Content of a Button can be any type of UIElement:
 
<Button Style="{StaticResource MenuItem}" Click="DisableDrawObject"  HorizontalAlignment="Right"   Foreground="Black"   >
   <Button.Content>
       <Image ........... />
   </Button.Content>
........
</Button>
0 Kudos
JoshV
by
Regular Contributor
The Content of a Button can be any type of UIElement:
 
<Button Style="{StaticResource MenuItem}" Click="DisableDrawObject"  HorizontalAlignment="Right"   Foreground="Black"   >
   <Button.Content>
       <Image ........... />
   </Button.Content>
........
</Button>


Wow that was easy.. Thanks.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Your are welcome.

Note also that I kept a 'Button' because you introduce it in your sample. But you could directly use an image as it was in the original sample. In this case you have to use the MouseLeftbuttonDown event instead of Click event.
0 Kudos
JoshV
by
Regular Contributor
Your are welcome.

Note also that I kept a 'Button' because you introduce it in your sample. But you could directly use an image as it was in the original sample. In this case you have to use the MouseLeftbuttonDown event instead of Click event.


Hey Dominique-

You don't happen to have the codebehind for the identify tool do you?  In the post I have below another developer tried zipping it to me and the file was corrupt after downloading.  I was able to add the tool to my toolbar and add the case to the ToolbarItemClicked event but haven't found the code that actually does the Identify process.  Just wondering

http://forums.arcgis.com/threads/9124-Identify..?p=28032&posted=1#post28032
0 Kudos