Table of Contents
Window Customization
Customize the appearance of the native macOS window, including title bar, toolbar, and vibrancy.
Enable Vibrancy
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.PlatformConfiguration;
using Microsoft.Maui.Controls.PlatformConfiguration.macOS;
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
this.On().SetVibrancyEffect(VibrancyEffect.Titlebar);
}
}
Set Title Bar Style
using UIKit;
public void SetUnifiedTitleBar()
{
var window = UIApplication.SharedApplication.Windows.FirstOrDefault();
window.Titlebar?.SetToolbarVisibility(true);
}
Touch Bar Support
Leverage the Touch Bar on supported MacBook Pro models directly from MAUI.
Adding a Button to the Touch Bar
using AppKit;
public void ConfigureTouchBar()
{
var touchBar = new NSTouchBar();
var button = new NSButton
{
Title = "Refresh",
Action = new ObjCRuntime.Selector("refreshClicked:")
};
touchBar.DefaultItemIdentifiers = new string[] { NSTouchBarItemIdentifier.Custom };
touchBar.AddItem(NSCustomTouchBarItem.FromIdentifier(NSTouchBarItemIdentifier.Custom, button));
NSApplication.SharedApplication.Windows.First().TouchBar = touchBar;
}
Native File Dialogs
Show macOS style open and save dialogs.
Open File Dialog
using AppKit;
public void ShowOpenDialog()
{
var panel = new NSOpenPanel
{
AllowsMultipleSelection = false,
CanChooseFiles = true,
CanChooseDirectories = false
};
if (panel.RunModal() == 1)
{
var url = panel.Url;
// Handle selected file
}
}
Save File Dialog
using AppKit;
public void ShowSaveDialog()
{
var panel = new NSSavePanel
{
NameFieldStringValue = "Untitled.txt",
AllowedFileTypes = new string[] { "txt", "md" }
};
if (panel.RunModal() == 1)
{
var url = panel.Url;
// Write data to url.Path
}
}
Apple Events & Activation
Respond to custom URL schemes and file associations.
Registering a URL Scheme
<Info.plist>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.example.myapp</string>
<key>CFBundleURLSchemes</key>
<array>
<string>myapp</string>
</array>
</dict>
</array>
</Info.plist>
Handling the URL in MAUI
using Microsoft.Maui;
using Microsoft.Maui.ApplicationModel;
public partial class App : Application
{
public App()
{
InitializeComponent();
AppInfo.Current.URIChanged += OnUriChanged;
}
private void OnUriChanged(object? sender, UriChangedEventArgs e)
{
// e.Uri => myapp://action?param=value
// Parse and navigate accordingly
}
}