Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hello All:

I want to create a menu like MS-Office 2007, Dinamically. Here's my XAML:

<Grid>
 <dxb:BarManager HorizontalAlignment="Left" Margin="15,15,0,0" Name="barManager1" VerticalAlignment="Top"></dxb:BarManager>
  <dxb:BarManager Name="BarManager">
       <dxr:RibbonControl Height="160" Name="RibbonControl" Width="Auto">
           <dxr:RibbonDefaultPageCategory>
           <dxr:RibbonPage Caption="Home" />
       </dxr:RibbonDefaultPageCategory>
   </dxr:RibbonControl>
 </dxb:BarManager>
</Grid>




And this is my Code behind:

public MenuBar()
{
  InitializeComponent();
  DevExpress.Xpf.Ribbon.ApplicationMenu applicationMenu = new DevExpress.Xpf.Ribbon.ApplicationMenu();
  applicationMenu.RightPane = new FrameworkElement();
  applicationMenu.RightPane.Width = 200;
  applicationMenu.RightPane.Height = 200;
  DevExpress.Xpf.Bars.BarItemLink item = new DevExpress.Xpf.Bars.BarItemLink();
  item.BarItemName = "Showing Item";

  applicationMenu.ItemLinks.Add(item);
  this.RibbonControl.ApplicationMenu = applicationMenu;
}


But I have a runtime error after clicking on ApplicationButton:
(Object reference not set to an instance of an object)
Wy? And What can I do for resolving this problem?
Posted
Updated 8-Feb-23 20:49pm
v2
Comments
thatraja 30-May-11 14:09pm    
In which line error occurs?
mariazingzing 31-May-11 0:42am    
Not a specific line. I see this message in a new page. If you run these code you will see.
Thanks.

1 solution

You need to declare one/some/all of the 13 RibbonControl Objects. Currently you have an instance of the object with no reference at all.

RibbonControl Class[^] shows you the methods. Also look at the left menubar with tons of more properties and classes.

As per above site, you will have something like this -
public class RibbonControl :
    Control,
    IRibbonControl,
    ILogicalChildrenContainer,
    IMergingSupport,
    IMultipleElementRegistratorSupport,
    IBarNameScopeSupport,
    IInputElement,
    IHierarchicalMergingSupport<RibbonControl>,
    IRuntimeCustomizationHost,
    IEventListenerClient,
    IKeyTipNavigationRoot,
    IKeyTipNavigationOwner,
    INavigationOwner,
    IBarsNavigationSupport,
    IBarsNavigationCompatibility,
    IMutableNavigationOwner,
    IMutableNavigationSupport,
    IThemedWindowSupport
 
Share this answer
 
Comments
Richard Deeming 9-Feb-23 4:12am    
Hopefully the OP managed to work it out some time in the last twelve years! :)
Andre Oosthuizen 9-Feb-23 12:19pm    
This is the second time this happened, under "unanswered questions" it pops up as recently loaded. I will be more vigilant on the date/time stamps.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900