Toolbar Example

Information for Developers

To add a custom toolbar, you need to use the INavContext interface. See INavContext Interface.

Here is an example assuming your class instance of INavContext is named “mNav.”

Copy
private void CreateCustombar()
{
ICustomToolBar toolBar = mNav.CreateCustomToolBar("My ToolBar");
toolBar.AddButton("My Button",newButtonCommand());
toolBar.AddSeparator();
toolBar.AddMenuButton(MyViewModel.MenuData);
}

ButtonCommand and MyViewModel are defined as follows.

Copy
public classButtonCommand :ICommand
{
public bool CanExecute(object parameter)
{
return true;
}
public voidExecute(object parameter)
{
MessageBox.Show("I got pressed!");
}
}
public static classRibbonViewModel
{
private static RibbonMenuData _menuData;
public staticRibbonMenuData MenuData
{
get
{
if (_menuData ==null)
{
BitmapImage image =new BitmapImage(new Uri("<ICON PATH>"));
_menuData =new RibbonMenuData()
{
Label ="My Menu",
SmallImage = image,
KeyTip ="D"
};
_menuData.ControlDataCollection.Add(new RibbonControlData()
{
MenuLabel = "item1"
});
_menuData.ControlDataCollection.Add(new RibbonControlData()
{
MenuLabel = "item2"
});
}
return _menuData;
}
}
}

Note The custom toolbar is only visible when the Flare interface is in “Tool Strip” mode.