I want to show a separate ribbon control. Can you show me how to create and display it ?
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 :

Download Wpfpalette0

Leave a Reply to WolfgangCancel reply