Select to view content in your preferred language

Adding toolbar items to a toolbar dynamically

613
1
01-02-2011 02:56 PM
PeterBrough
New Contributor
I'm adding toolbar items to a toolbar at run-time. The toolbar items collection is being populated OK but the toolbar items are not displaying on the toolbar. If I include hard-coded toolbar items in my XAML they are diaplayed OK but any dynamically added ones are not. I've compared the attributes of the static items with the dynamic items but can't see what I'm missing - it's probably something simple. A snippet from my code-behind is below - this code is called after a collection of eGISToolBarItems to be added to the uxToolBar has been retrieved from a database repository. Any help would be much appreciated.

if (uxToolbar.Items == null)
{
  uxToolbar.Items = new ToolbarItemCollection();
}

foreach (eGISToolBarItem item in toolBarItemData)
{
  ToolbarItem tbi = new ToolbarItem();
  Image img = new Image();
  ImageSourceConverter isc = new ImageSourceConverter();
  img.Source = (ImageSource)isc.ConvertFromString("Assets/Images/" + item.ImageFile);
  ToolTipService.SetToolTip(img, item.ToolTip);
  img.Stretch = Stretch.UniformToFill;
  img.Margin = new Thickness(5);
  img.VerticalAlignment = VerticalAlignment.Center;
  img.HorizontalAlignment = HorizontalAlignment.Center;
  tbi.Content = (FrameworkElement)img;
  uxToolbar.Items.Add(tbi);
}
0 Kudos
1 Reply
DominiqueBroux
Esri Frequent Contributor
Unfortunately I didn't find out any way to add items dynamically.
My best suggestion is you to manage your own toolbar which is basically a panel with buttons inside.
0 Kudos