ExtrabbitCode Inventor ModernUi

Getting Started

Install ExtrabbitCode.Inventor.ModernUi and theme your first window.

Install

Add the NuGet package to your add-in project:

dotnet add package ExtrabbitCode.Inventor.ModernUi

The package targets net8.0-windows with WPF.

Starting a new add-in from scratch? The ExtrabbitCode.Inventor.Core.Template is a ready-to-use Inventor add-in starter (isolated load context, ribbon/command scaffolding, deploy plumbing) that uses ModernUi as its default UI.

Theme a window

There are two ways to get a themed window. Use ModernWindow as a base, or call ModernUi.Apply on any existing Window.

using ExtrabbitCode.Inventor.ModernUi;

// Option A - derive from ModernWindow (themes itself in the constructor):
var dialog = new ModernWindow(Theme.Dark) { Title = "My dialog", Content = myControl };

// Option B - apply to an existing Window:
ModernUi.Apply(existingWindow, Theme.Dark);

Both inject the colours, font and control styles into that window's resources only - nothing is written to Application.Current.Resources.

Match Inventor's theme and font

Read the active theme and UI font from the Inventor API and pass them in, so your dialog matches Inventor exactly:

Theme theme = app.ThemeManager.ActiveTheme.Name == "LightTheme"
    ? Theme.Light
    : Theme.Dark;

FontOptions font = FontOptions.FromInventor(
    app.GeneralOptions.TextAppearance, // family
    app.GeneralOptions.TextSize);      // size in points

var dialog = new ModernWindow(theme, font: font)
{
    Title = "Attributes",
    Content = myControl,
};

Own the dialog to Inventor

So the window stays on top of Inventor and closes with it, set Inventor's main window as its owner:

using System.Windows.Interop;

_ = new WindowInteropHelper(dialog) { Owner = new IntPtr(app.MainFrameHWND) };
dialog.Show();

WindowInteropHelper is a standard WPF type (System.Windows.Interop), not part of this library - it lets you set a native window as the owner of a WPF window. app.MainFrameHWND is the Inventor API's handle for Inventor's main window.

Use the controls

Inside a themed window, the standard WPF controls are styled automatically - just write normal XAML:

<StackPanel>
  <TextBox Width="240" />
  <Button Content="OK" Style="{DynamicResource AccentButton}" Margin="0,8,0,0" />
</StackPanel>

See Controls for every styled control, and Theming for palettes, fonts and design tokens.

On this page