Loading...
Loading...
Guide for using the Microsoft Fluent UI Blazor component library (Microsoft.FluentUI.AspNetCore.Components NuGet package) in Blazor applications. Use this when the user is building a Blazor app with Fluent UI components, setting up the library, using FluentUI components like FluentButton, FluentDataGrid, FluentDialog, FluentToast, FluentNavMenu, FluentTextField, FluentSelect, FluentAutocomplete, FluentDesignTheme, or any component prefixed with "Fluent". Also use when troubleshooting missing providers, JS interop issues, or theming.
npx skill4agent add github/awesome-copilot fluentui-blazor<script><link><script><link>MainLayout.razor<FluentToastProvider />
<FluentDialogProvider />
<FluentMessageBarProvider />
<FluentTooltipProvider />
<FluentKeyCodeProvider />builder.Services.AddFluentUIComponents();
// Or with configuration:
builder.Services.AddFluentUIComponents(options =>
{
options.UseTooltipServiceProvider = true; // default: true
options.ServiceLifetime = ServiceLifetime.Scoped; // default
});ServiceLifetime.ScopedServiceLifetime.SingletonServiceLifetime.TransientNotSupportedExceptiondotnet add package Microsoft.FluentUI.AspNetCore.Components.Icons@using@using Icons = Microsoft.FluentUI.AspNetCore.Components.Icons
<FluentIcon Value="@(Icons.Regular.Size24.Save)" />
<FluentIcon Value="@(Icons.Filled.Size20.Delete)" Color="@Color.Error" />Icons.[Variant].[Size].[Name]RegularFilledSize12Size16Size20Size24Size28Size32Size48Icon.FromImageUrl("/path/to/image.png")FluentSelect<TOption>FluentCombobox<TOption>FluentListbox<TOption>FluentAutocomplete<TOption><InputSelect>ItemsIEnumerable<TOption>OptionTextFunc<TOption, string?>OptionValueFunc<TOption, string?>SelectedOptionSelectedOptionChangedSelectedOptionsSelectedOptionsChanged<FluentSelect Items="@countries"
OptionText="@(c => c.Name)"
OptionValue="@(c => c.Code)"
@bind-SelectedOption="@selectedCountry"
Label="Country" />@* WRONG — do not use InputSelect pattern *@
<FluentSelect @bind-Value="@selectedValue">
<option value="1">One</option>
</FluentSelect>ValueTextValueOnOptionsSearchMultiple="true"<FluentAutocomplete TOption="Person"
OnOptionsSearch="@OnSearch"
OptionText="@(p => p.FullName)"
@bind-SelectedOptions="@selectedPeople"
Label="Search people" />
@code {
private void OnSearch(OptionsSearchEventArgs<Person> args)
{
args.Items = allPeople.Where(p =>
p.FullName.Contains(args.Text, StringComparison.OrdinalIgnoreCase));
}
}<FluentDialog>IDialogContentComponent<TData>public partial class EditPersonDialog : IDialogContentComponent<Person>
{
[Parameter] public Person Content { get; set; } = default!;
[CascadingParameter] public FluentDialog Dialog { get; set; } = default!;
private async Task SaveAsync()
{
await Dialog.CloseAsync(Content);
}
private async Task CancelAsync()
{
await Dialog.CancelAsync();
}
}IDialogService[Inject] private IDialogService DialogService { get; set; } = default!;
private async Task ShowEditDialog()
{
var dialog = await DialogService.ShowDialogAsync<EditPersonDialog, Person>(
person,
new DialogParameters
{
Title = "Edit Person",
PrimaryAction = "Save",
SecondaryAction = "Cancel",
Width = "500px",
PreventDismissOnOverlayClick = true,
});
var result = await dialog.Result;
if (!result.Cancelled)
{
var updatedPerson = result.Data as Person;
}
}await DialogService.ShowConfirmationAsync("Are you sure?", "Yes", "No");
await DialogService.ShowSuccessAsync("Done!");
await DialogService.ShowErrorAsync("Something went wrong.");[Inject] private IToastService ToastService { get; set; } = default!;
ToastService.ShowSuccess("Item saved successfully");
ToastService.ShowError("Failed to save");
ToastService.ShowWarning("Check your input");
ToastService.ShowInfo("New update available");FluentToastProviderPositionTopRightTimeoutMaxToastCountOnInitializedOnAfterRenderAsync<FluentDesignTheme Mode="DesignThemeModes.System"
OfficeColor="OfficeColor.Teams"
StorageName="mytheme" />FluentEditFormFluentWizardEditForm<EditForm Model="@model" OnValidSubmit="HandleSubmit">
<DataAnnotationsValidator />
<FluentTextField @bind-Value="@model.Name" Label="Name" Required />
<FluentSelect Items="@options"
OptionText="@(o => o.Label)"
@bind-SelectedOption="@model.Category"
Label="Category" />
<FluentValidationSummary />
<FluentButton Type="ButtonType.Submit" Appearance="Appearance.Accent">Save</FluentButton>
</EditForm>FluentValidationMessageFluentValidationSummary