Loading...
Loading...
Compare original and translation side by side
<script><link><script><link><script><link><script><link>MainLayout.razor<FluentToastProvider />
<FluentDialogProvider />
<FluentMessageBarProvider />
<FluentTooltipProvider />
<FluentKeyCodeProvider />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.TransientNotSupportedExceptionbuilder.Services.AddFluentUIComponents();
// 或带配置的注册方式:
builder.Services.AddFluentUIComponents(options =>
{
options.UseTooltipServiceProvider = true; // 默认值:true
options.ServiceLifetime = ServiceLifetime.Scoped; // 默认值
});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")dotnet 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>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" />@* 错误 — 不要使用InputSelect的模式 *@
<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));
}
}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.");<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");FluentToastProviderPositionTopRightTimeoutMaxToastCount[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" />OnInitializedOnAfterRenderAsync<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>FluentValidationMessageFluentValidationSummaryFluentWizardFluentEditFormEditForm<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