Displaying Ribbon Control in the palette

By Balaji Ramamoorthy

Issue

I want to show a separate ribbon control. Can you show me how to create and display it ?

Solution

The RibbonControl is a class that inherits “System.Windows.Controls.Control” and so requires a WPF host (Ex: WPF User control) to display it.

The WPF User control can be associated with the AutoCAD palette.

Only the pertinent code is shown here. Please download the attachment for the sample project.

if(_ps == null)
{
    _ps = new PaletteSet("WPF Palette");
    _ps.Size = new Size(400, 600);
    _ps.DockEnabled 
            = (DockSides)((int)DockSides.Left + (int)DockSides.Right);
    MyWPFUserControl uc = new MyWPFUserControl();
 
    Autodesk.Windows.RibbonControl ribControl 
                        = new Autodesk.Windows.RibbonControl();
 
    RibbonTab ribTab = new RibbonTab();
    ribTab.Title = "Test";
    ribTab.Id = "Test";
    ribControl.Tabs.Add(ribTab);
 
    RibbonPanelSource ribSourcePanel = new RibbonPanelSource();
    ribSourcePanel.Title = "My Tools";
    ribSourcePanel.DialogLauncher =  new RibbonCommandItem();
    ribSourcePanel.DialogLauncher.CommandHandler 
                                    = new AdskCommandHandler();
 
    //Add a Panel
    RibbonPanel ribPanel = new RibbonPanel();
    ribPanel.Source = ribSourcePanel;
    ribTab.Panels.Add(ribPanel);
 
    //Create button
    RibbonButton ribButton1 = new RibbonButton();
    ribButton1.Text = "Line" + "n" + "Generator";
    ribButton1.CommandParameter = "Line ";
    ribButton1.ShowText = true;
    ribButton1.LargeImage 
        = Images.getBitmap((Bitmap)_resourceManager.GetObject("LineImage"));
    ribButton1.Image 
        = Images.getBitmap((Bitmap)_resourceManager.GetObject("LineImage"));
    ribButton1.Size = RibbonItemSize.Large;
    ribButton1.Orientation = System.Windows.Controls.Orientation.Vertical;
    ribButton1.ShowImage = true;
    ribButton1.ShowText = true;
    ribButton1.CommandHandler = new AdskCommandHandler();
    ribSourcePanel.Items.Add(ribButton1);
 
    uc.Content = ribControl;
 
    _ps.AddVisual("Test", uc);
}
 
_ps.KeepFocus = true;
_ps.Visible = true;

Here is a screenshot of the ribbon displayed in a palette :
1
Download Wpfpalette0


Comments

4 responses to “Displaying Ribbon Control in the palette”

  1. Wolfgang Avatar
    Wolfgang

    Hi,
    adding a Ribbon Control to a palette works fine (WPF). One question: I want to get the actual height of the ribbon control (changes through cycling from full ribbon/minimized to panels/minimzed to tabs) to place some controls directly and dynamically below the ribbon control.
    – Wolfgang

  2. Hi Wolfgang,
    Using a WPF ContentControl in the user control and settings its Content to the RibbonControl will automatically consider the resizing.
    Here is a sample code snippet assuming that the name of the content control is “MyCC” :
    System.Windows.Controls.ContentControl myCC = uc.FindName(“MyCC”) as System.Windows.Controls.ContentControl;
    myCC.Content = ribControl;
    Regards,
    Balaji

  3. Hi, I have some query ,I want to know, what are the benefits or reason of developing the tool palettes in .Net? What are the points that makes us to use .net for developing it?
    As we can simply use Tool Palettes features in AutoCAD’s Menu, then what are the extra thing that can be done pragmatically for Tool Palettes.?

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading