The Blazor Button Group component is used to organize IgbToggleButton's into styled button groups with horizontal/vertical alignment, single/multiple selection and toggling.
Blazor Button Example
EXAMPLE
MODULES
RAZOR
CSS
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using IgniteUI.Blazor.Controls; // for registering Ignite UI modulesnamespaceInfragistics.Samples
{
publicclassProgram
{
publicstaticasync Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
// registering Ignite UI modules
builder.Services.AddIgniteUIBlazor(typeof(IgbButtonGroupModule));
await builder.Build().RunAsync();
}
}
}cs
/*
CSS styles are loaded from the shared CSS file located at:
https://static.infragistics.com/xplatform/css/samples/
*/css
Usage
Before using the IgbButtonGroup, you need to register it as follows:
// in Program.cs file
builder.Services.AddIgniteUIBlazor(typeof(IgbButtonGroupModule));
razor
You will also need to link an additional CSS file to apply the styling to the IgbButtonGroup component. The following needs to be placed in the wwwroot/index.html file in a Blazor Web Assembly project or the Pages/_Host.cshtml file in a Blazor Server project:
For a complete introduction to the Ignite UI for Blazor, read the Getting Started topic.
Now that you have the Ignite UI for Blazor Button Group imported, you can start with a basic configuration of the IgbButtonGroup and its buttons.
Use the IgbButtonGroup selector to wrap your IgbToggleButtons and display them into a button group. If you want a button to be selected by default, use the Selected attribute:
Use the Alignment property to set the orientation of the buttons in the button group.
EXAMPLE
MODULES
RAZOR
CSS
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using IgniteUI.Blazor.Controls; // for registering Ignite UI modulesnamespaceInfragistics.Samples
{
publicclassProgram
{
publicstaticasync Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
// registering Ignite UI modules
builder.Services.AddIgniteUIBlazor(typeof(IgbButtonGroupModule));
await builder.Build().RunAsync();
}
}
}cs
@using IgniteUI.Blazor.Controls<style>
igc-button-group {
width: 200px;
}
igc-ripple {
--color: gray;
}
</style><divclass="container sample"><IgbButtonGroupAlignment="ContentOrientation.Vertical"><IgbToggleButtonValue="sofia">
Sofia
<IgbRipple /></IgbToggleButton><IgbToggleButtonValue="london">
London
<IgbRipple /></IgbToggleButton><IgbToggleButtonValue="new york"Selected="true">
New York
<IgbRipple /></IgbToggleButton><IgbToggleButtonValue="tokyo">
Tokyo
<IgbRipple /></IgbToggleButton></IgbButtonGroup></div>@code {}razor
/*
CSS styles are loaded from the shared CSS file located at:
https://static.infragistics.com/xplatform/css/samples/
*/css
Selection
In order to configure the Ignite UI for Blazor IgbButtonGroup selection, you could use its Selection property. This property accepts the following three modes:
single - default selection mode of the button group. A single button can be selected/deselected by the user.
single-required - mimics a radio group behavior. Only one button can be selected and once initial selection is made, deselection is not possible through user interaction.
multiple - multiple buttons in the group can be selected and deselected.
The sample below demonstrates the exposed IgbButtonGroup selection modes:
EXAMPLE
MODULES
RAZOR
CSS
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using IgniteUI.Blazor.Controls; // for registering Ignite UI modulesnamespaceInfragistics.Samples
{
publicclassProgram
{
publicstaticasync Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
// registering Ignite UI modules
builder.Services.AddIgniteUIBlazor(typeof(IgbButtonGroupModule));
await builder.Build().RunAsync();
}
}
}cs
Setting IgbToggleButton Value attribute is mandatory for using the SelectedItems property of the IgbButtonGroup.
Size
The --ig-size CSS custom property can be used to control the size of the button group.
EXAMPLE
MODULES
RAZOR
CSS
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using IgniteUI.Blazor.Controls; // for registering Ignite UI modulesnamespaceInfragistics.Samples
{
publicclassProgram
{
publicstaticasync Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
// registering Ignite UI modules
builder.Services.AddIgniteUIBlazor(typeof(IgbButtonGroupModule));
await builder.Build().RunAsync();
}
}
}cs
@using IgniteUI.Blazor.Controls<divclass="container sample"><IgbButtonGroupstyle="@style"Select="OnSelect"><IgbToggleButtonValue="small">
Small
</IgbToggleButton><IgbToggleButtonValue="medium">
Medium
</IgbToggleButton><IgbToggleButtonValue="large"Selected="true">
Large
</IgbToggleButton></IgbButtonGroup></div>@code {privatestring style = "--ig-size: var(--ig-size-large)";
privatevoidOnSelect(IgbComponentValueChangedEventArgs args)
{
this.style = $"--ig-size: var(--ig-size-{args.Detail})";
}
}razor
/*
CSS styles are loaded from the shared CSS file located at:
https://static.infragistics.com/xplatform/css/samples/
*/css
Styling
The IgbButtonGroup component exposes group CSS part that allows us to style the button group container.
Also, the IgbToggleButtons provide toggle CSS part that could be used to style the button element.
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using IgniteUI.Blazor.Controls; // for registering Ignite UI modulesnamespaceInfragistics.Samples
{
publicclassProgram
{
publicstaticasync Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
// registering Ignite UI modules
builder.Services.AddIgniteUIBlazor(typeof(IgbButtonGroupModule));
await builder.Build().RunAsync();
}
}
}cs