Select to view content in your preferred language

Changing Toolbar Image in Code Behind

650
2
09-21-2010 06:46 AM
PaulHuppé
Deactivated User
Hi,

I am trying to change the image shown in the toolbar when the user selects a tool in the toolbar.  I tried to change the Source property of the image of the selected tool in the method "MyToolbar_ToolBarItemClicked" which is called when the user selects a tool.  When I click on a tool, I get the following message:

Microsoft JScript runtime error: Unhandled Error in Silverlight Application Object reference not set to an instance of an object.   at LacationMapViewer.MainPage.MyToolbar_ToolbarItemClicked(Object sender, SelectedToolbarItemArgs e)
   at ESRI.ArcGIS.Client.Toolkit.Toolbar.contentElement_MouseLeftButtonDown(Object sender, MouseButtonEventArgs e)
   at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)

As anyone tried to do this?
Paul
0 Kudos
2 Replies
JenniferNery
Esri Regular Contributor
How are you setting the toolbar item's image?  I tried the following and it worked for me without exception.

var toolbarItem = MyToolbar.Items[e.Index];
var toolbarImage = toolbarItem.Content;
if (toolbarImage is Image)
  (toolbarImage as Image).Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri("/Assets/images/i_globe.png", System.UriKind.RelativeOrAbsolute));  
0 Kudos
PaulHuppé
Deactivated User
That worked, thanks Jennifer.
0 Kudos