Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey there!
I have created a custom ribbon but now I need to arrange the buttons as I need but it doesn't fit well. So is there any way to fix the size and arrange it as we need. I want to arrange the buttons as shown in the below SS:
But mine look like this:
Edit:
I forgot to share the code, so here is the code:
private void CreateRibbon()
{
try
{
RibbonControl ribCntrl = Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.RibbonControl;
if (ribCntrl == null) return;
var existingTab = ribCntrl.Tabs.FirstOrDefault(t => t.Id == MY_TAB_ID);
if (existingTab != null && existingTab.IsActive) return;
if (existingTab != null)
{
ribCntrl.Tabs.Remove(existingTab);
}
RibbonTab ribTab = new RibbonTab { Title = "Advanced Tools", Id = MY_TAB_ID };
ribCntrl.Tabs.Add(ribTab);
AddSimplePanel(ribTab, "CAD Tools");
if (wasActive)
ribTab.IsActive = true;
ribTab.Activated += RibTab_Activated;
ribTab.Deactivated += RibTab_Deactivated;
}
catch (Exception ex)
{
Application.DocumentManager.MdiActiveDocument?.Editor.WriteMessage($"\nError creating ribbon tab: {ex.Message}");
}
}
private void AddSimplePanel(RibbonTab tab, string panelTitle)
{
RibbonRowBreak rbrk = new RibbonRowBreak();
RibbonSubPanelSource rspl = new RibbonSubPanelSource();
RibbonPanelSource panelSource = new RibbonPanelSource { Title = panelTitle };
RibbonPanel ribPanel = new RibbonPanel { Source = panelSource };
tab.Panels.Add(ribPanel);
RibbonRowPanel rowPanel = new RibbonRowPanel();
panelSource.Items.Add(rowPanel);
var buttons = new[]
{
("Command 1", "COMMAND1 "),
("Command 2", "COMMAND1 "),
("Command 3", "COMMAND1 "),
};
int count = 0;
int index = 0;
foreach (var (text, command) in buttons)
{
var button = new RibbonButton
{
Text = text,
ShowText = true,
Orientation = System.Windows.Controls.Orientation.Horizontal,
Size = RibbonItemSize.Standard,
CommandParameter = command,
};
button.CommandHandler = new RelayCommand();
rowPanel.Items.Add(button);
}
}
Solved! Go to Solution.