Toggle Button Groups are based on checkboxes shown as buttons in different states. This allows users to choose between different options and see what option is currently selected.
Bootstrap is a popular CSS Framework for developing responsive and mobile-first websites. It is included into the Visual Studio Blazor templates and can easily be used in Blazor. But the Toggle Button Groups based on radio buttons normally requires JavaScript. This article shows how to use without JavaScript.
As the first step, we define a data Template, holding the shown options, the currently selected options and as specialty a method used in razor syntax to modify the class attribute.
GetActive is a very special method, only if the option is the selected one, it returns "active", what is the CSS class name required by the active element. So this can be used in the razor file to extend "active" CSS class to the class tag on the active button.
This is a basic principle in Blazor in case you need to define a CSS class depending on some runtime variables.
The second step is to define the botton group.
So we use the HTML syntax from the sample and loop through all options. In the class attribute of the label, we use our defined method 'GetActive' to add "active" only to the active button. For checked, we directly use a compare between optionName and current SelectedOption, that is changed in the onchange event. One last thing is missing the Property in the component holding the information.
Just define a ToggleGroupInfo and set it as the GroupInfo property.
In case the view needs to be changed with changing the selected option, it is helpful to enhance the ToggleGroupInfo class to implement INotifyPropertyChanged. After this, you may add the usage to the code to reload.
blazor toggle switch
blazor toggle class
asp.net toggle switch
blazor tutorial
blazor webassembly
blazor train
blazor server
blazor webassembly tutorial
blazor app
blazor app tutorial
blazor application
blazor bootstrap
blazor basics
blazor beginner
blazor bootstrap 5
blazor components
blazor c#
blazor css
blazor client side
blazor c# tutorial
blazor course
c sharp blazor
blazor bootstrap 4
blazor bootstrap dropdown
blazor bootstrap not working
Auf dieser Seite können Sie das Online-Video Blazor (ASP.NET Core) - Bootstrap Toggle Button Group mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Sarrawy Dev 27 April 2021 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 1,548 Mal angesehen und es wurde von like den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!