(options =>
{
options.Modal = true;
options.Alignment = DialogAlignment.End;
options.Header.CloseAction.Visible = true;
options.Header.InfoAction.Visible = true;
options.Header.InfoAction.OnClickAsync = async (dialog) => { await Task.CompletedTask; Console.WriteLine("Info action clicked"); };
options.Header.AddAction(action =>
{
action.Icon = new Icons.Regular.Size20.Settings();
action.Label = "Settings";
action.OnClickAsync = async (dialog) => { await Task.CompletedTask; Console.WriteLine("Settings action clicked"); };
});
options.Parameters.Add(nameof(Dialog.SimpleDialog.Name), "John"); // Simple type
options.Parameters.Add(nameof(Dialog.SimpleDialog.Person), John); // Updatable object
});
if (result.Cancelled)
{
Console.WriteLine($"Dialog Canceled: {result.Value}");
}
else
{
Console.WriteLine($"Dialog Saved: {result.Value}");
}
}
}
```
--------------------------------
### Customize Fluent Menu Item with Slots
Source: https://fluentui-blazor-v5.azurewebsites.net/Menu
Use slots directly for advanced customization of Fluent menu items when component parameters like IconIndicator, IconStart, IconEnd, and IconSubmenu are not sufficient. This example demonstrates adding custom content to indicator, start, end, and submenu-glyph slots.
```blazor
Item 1
☑️
💙
Ctrl+S
→
Submenu 1
```
--------------------------------
### Basic FluentWizard Implementation
Source: https://fluentui-blazor-v5.azurewebsites.net/Wizard
Demonstrates the basic structure of a FluentWizard with multiple FluentWizardStep components. Includes configuration for step numbering, borders, and an OnFinish event handler.
```blazor
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ut nisi eget dolor semper
luctus vitae a nulla. Cras semper eros sed lacinia tincidunt. Mauris dignissim ullamcorper dolor,
ut blandit dui ullamcorper faucibus. Interdum et malesuada fames ac ante ipsum.
Maecenas sed justo ac sapien venenatis ullamcorper. Sed maximus nunc non venenatis euismod.
Fusce vel porta ex, imperdiet molestie nisl. Vestibulum eu ultricies mauris, eget aliquam quam.
Nunc dignissim tortor eget lacus porta tristique. Nunc in posuere dui. Cras ligula ex,
ullamcorper in gravida in, euismod vitae purus. Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Aliquam at velit leo. Suspendisse potenti. Cras dictum eu augue in laoreet.
Phasellus quis augue convallis, congue velit ac, aliquam ex. In egestas porttitor massa
aliquet porttitor. Donec bibendum faucibus urna vitae elementum. Phasellus vitae efficitur
turpis, eget molestie ipsum.
Ut iaculis sed magna efficitur tempor. Vestibulum est erat, imperdiet in diam ac,
aliquam tempus sapien. Nam rutrum mi at enim mattis, non mollis diam molestie.
Cras sodales dui libero, sit amet cursus sapien elementum ac. Nulla euismod nisi sem.
@code
{
void OnStepChange(FluentWizardStepChangeEventArgs e)
{
Console.WriteLine("Step changed to {0}", e.TargetIndex);
}
void OnFinished()
{
Console.WriteLine("Wizard has been finished");
}
}
```
--------------------------------
### Programmatically Expand/Collapse Accordion Items
Source: https://fluentui-blazor-v5.azurewebsites.net/Accordion
Use the @ref attribute to get a reference to the FluentAccordion component and call ExpandItemAsync or CollapseItemAsync with the item's ID. Ensure each FluentAccordionItem has a unique Id. The example also shows how to bind to the Expanded property of an item and handle item change events.
```csharp
Expand item 2
Collapse item 4
Panel one content
Panel two content
Panel three content
Panel four content
Last changed accordion item: @headerText
Expanded: @changed?.Expanded
@code {
FluentAccordion? accordion;
FluentAccordionItem? changed;
string? headerText;
bool expanded = true;
private async Task ExpandItem2Async()
{
if (accordion is not null)
{
await accordion.ExpandItemAsync("item2");
}
}
private async Task CollapseItem4Async()
{
if (accordion is not null)
{
await accordion.CollapseItemAsync("item4");
}
}
private void HandleOnAccordionItemChange(AccordionItemEventArgs args)
{
changed = args.Item;
headerText = args.HeaderText;
}
}
```
--------------------------------
### Basic FluentSwitch Example
Source: https://fluentui-blazor-v5.azurewebsites.net/Switch
Demonstrates a basic FluentSwitch component bound to a boolean value. Use this for simple on/off or show/hide scenarios.
```html
Switch value: @value
@code {
bool value = false;
}
```
--------------------------------
### Verify Global .NET Tool Installation
Source: https://fluentui-blazor-v5.azurewebsites.net/Mcp/Installation
Use this command to check if the fluentui-mcp tool is installed globally on your system.
```bash
dotnet tool list -g
```
--------------------------------
### Install Fluent UI Blazor NuGet Package
Source: https://fluentui-blazor-v5.azurewebsites.net/installation
Add the Microsoft.FluentUI.AspNetCore.Components package to your project using the .NET CLI. Use the --prerelease flag for pre-release versions.
```bash
dotnet add package Microsoft.FluentUI.AspNetCore.Components --prerelease
```
```bash
dotnet add package Microsoft.FluentUI.AspNetCore.Components.Icons
```
--------------------------------
### Specific vs. Vague Prompt Example
Source: https://fluentui-blazor-v5.azurewebsites.net/Mcp/Examples
Illustrates the difference between a specific and a vague prompt for creating a UI component. Specific prompts yield better results.
```text
❌ "Make a table"
✅ "Create a FluentDataGrid with sortable columns for Name and Date,
and pagination with 20 items per page"
```
--------------------------------
### Side-by-Side Popover Examples
Source: https://fluentui-blazor-v5.azurewebsites.net/Popover
Shows two Popover components side-by-side, each anchored to its own button. This example illustrates controlling multiple popovers independently.
```html
Open Popover
Example content for the
Popover component
Open Popover
Example content for the
Popover component
@code
{
bool LeftOpened = false;
bool RightOpened = false;
}
```
--------------------------------
### Open and Handle Customized Dialog
Source: https://fluentui-blazor-v5.azurewebsites.net/Dialog
This example demonstrates opening a customized dialog and handling its result. It shows how to pass simple types and updatable objects as parameters, and how to react to state changes and dialog closure.
```csharp
@inject IDialogService DialogService
Open Dialog
John: @John
@code
{
private Dialog.PersonDetails John = new() { Age = "20" };
private async Task OpenDialogAsync()
{
var result = await DialogService.ShowDialogAsync(options =>
{
options.Header.Title = "Dialog Title";
options.Header.CloseAction.Visible = true;
options.Parameters.Add(nameof(Dialog.CustomizedDialog.Name), "John"); // Simple type
options.Parameters.Add(nameof(Dialog.CustomizedDialog.Person), John); // Updatable object
options.OnStateChange = (e) =>
{
Console.WriteLine($"State changed: {e.State}");
};
});
if (result.Cancelled)
{
Console.WriteLine($"Dialog Canceled: {result.Value}");
}
else
{
Console.WriteLine($"Dialog Saved: {result.Value}");
}
}
}
```
--------------------------------
### Example PackageReference
Source: https://fluentui-blazor-v5.azurewebsites.net/Mcp/VersionCompatibility
This is the expected `PackageReference` XML that should be used in your project's `.csproj` file to ensure compatibility with the MCP server.
```xml
```
--------------------------------
### DataGrid with EmptyContent Example
Source: https://fluentui-blazor-v5.azurewebsites.net/DataGrid/LoadingAndEmptyContent
This example shows how to define custom content to display when the DataGrid has no items. It includes a FluentStack with an icon and text, and a switch to clear data.
```blazor
Nothing to see here. Carry on!
Simulate data loading
@code {
FluentDataGrid? grid;
FluentSwitch? _clearToggle;
string switchLabel = "Clear data";
bool _clearItems = false;
public record SampleGridData(string Item1, string Item2, string Item3, string Item4);
IQueryable? items = Enumerable.Empty().AsQueryable();
private IQueryable GenerateSampleGridData(int size)
{
SampleGridData[] data = new SampleGridData[size];
for (int i = 0; i < size; i++)
{
data[i] = new SampleGridData($"This {i}-1", $"is {i}-2", $"some {i}-3", $"data {i}-4");
}
return data.AsQueryable();
}
protected override void OnInitialized()
{
items = GenerateSampleGridData(100);
}
private async Task SimulateDataLoading()
{
_clearItems = false;
grid?.SetLoadingState(true);
items = null;
await Task.Delay(1500);
items = GenerateSampleGridData(100);
grid?.SetLoadingState(false);
}
private void ToggleItems()
{
if (_clearItems)
{
items = null;
switchLabel = "Restore data";
}
else
{
items = GenerateSampleGridData(100);
switchLabel = "Clear data";
}
}
}
```
--------------------------------
### Simple AppBar Example
Source: https://fluentui-blazor-v5.azurewebsites.net/AppBar
This snippet demonstrates a basic Fluent UI Blazor AppBar with various configuration options. It includes switches to control search visibility, orientation (horizontal/vertical), and bar hiding. The AppBar contains multiple items with icons, text, and counts.
```csharp
@{
string stylevalue = $"background-color: var(--colorNeutralBackground5); overflow: hidden; resize: {(_vertical ? "vertical; width: 86px; height: 320px;" : "horizontal;width: 440px; height: 78px;")} padding: 10px;";
}
@code {
private bool _vertical = true;
private bool _showSearch = true;
private bool _hideBar = false;
private static Icon ResourcesIcon(bool active = false) =>
active ? new Icons.Filled.Size24.AppFolder()
: new Icons.Regular.Size24.AppFolder();
private static Icon ConsoleLogsIcon(bool active = false) =>
active ? new Icons.Filled.Size24.SlideText()
: new Icons.Regular.Size24.SlideText();
private static Icon StructuredLogsIcon(bool active = false) =>
active ? new Icons.Filled.Size24.SlideTextSparkle()
: new Icons.Regular.Size24.SlideTextSparkle();
private static Icon TracesIcon(bool active = false) =>
active ? new Icons.Filled.Size24.GanttChart()
: new Icons.Regular.Size24.GanttChart();
private static Icon MetricsIcon(bool active = false) =>
active ? new Icons.Filled.Size24.ChartMultiple()
: new Icons.Regular.Size24.ChartMultiple();
private void HandlePopover(bool visible) => Console.WriteLine($"Popover visibility changed to {visible}");
private void HandleOrientationChanged()
{
Console.WriteLine($"Orientation changed to {(_vertical ? "vertical" : "horizontal")}");
}
private void HandleHideBarChanged()
{
Console.WriteLine($"@(_hideBar ? "Hiding" : "Showing") active bar");
}
}
```
--------------------------------
### FluentColorPickerInput Example with View and Text Input Toggling
Source: https://fluentui-blazor-v5.azurewebsites.net/ColorPicker
Demonstrates how to use FluentColorPickerInput, allowing runtime switching between different picker views and toggling the visibility of the text input.
```cshtml
Selected Color: @SelectedColor
@code
{
string? SelectedColor = "#FF0000";
ColorPickerView SelectedView = ColorPickerView.SwatchPalette;
bool HideTextInput = false;
}
```
--------------------------------
### CompoundButton with Long Text Example
Source: https://fluentui-blazor-v5.azurewebsites.net/Buttons/CompoundButton
Demonstrates how to use FluentCompoundButton with both short and long text labels, including a description. The example also shows how to apply a maximum width to a button.
```html
Description content
Long text wraps after it hits the max width of the component
Description content
```
--------------------------------
### Basic FluentNav with Various Item Types
Source: https://fluentui-blazor-v5.azurewebsites.net/Nav
Demonstrates the structure of a FluentNav component, including NavItems with Href and OnClick handlers, NavCategories, NavSectionHeaders, and a FluentDivider. This example shows how to create a hierarchical navigation structure.
```csharp
@using Microsoft.FluentUI.AspNetCore.Components
@using Microsoft.FluentUI.AspNetCore.Components.Extensions
@inject IDialogService DialogService
Dashboard
Announcements
Employee Spotlight
Profile Search
Performance Reviews
Openings
Submissions
Interviews
Health Plans
Plan Information
Fund Performance
Training Programs
Openings
Submissions
```