Comments (5)
I see the issue now. I was obviously thrown off by trying to use @bind-Value that I normally would use. Which of course it won't let me use. I never again attempted to "bind" my value to the switch as I assumed it would give me the same error. Value="@groupValue" works as intended and allows me to start it with a true value.
from mudblazor.
Simply set the Value
property to true via a variable - https://try.mudblazor.com/snippet/mamIETbBJdVjwnGH
from mudblazor.
Seems like the simple solution, but on my machine if I set Value="true" I cannot uncheck the switch. It stays true all the time and doesn't matter what I do. Everything else in the page works. In the Try MudBlazor thing it works as expected. Here is my exact code.
<MudSwitch @ref="groupBySwitch" Value="true" ValueChanged="@((bool val) => GroupByChanged(val))" Label="@(!groupValue ? "Grouped by Agency" : "Grouped by Entity")" LabelPosition="LabelPosition.Start" />
// Toggle Group By
private async Task GroupByChanged(bool isChecked)
{
if (isChecked)
{
groupValue = true;
}
else
{
groupValue = false;
}
dataGrid.GroupItems();
}
from mudblazor.
Great. Feel free to close this issue if you're satisfied.
from mudblazor.
Another alternative in .NET 7+:
<MudSwitch T="bool" @bind-Value:get="_isSelected" @bind-Value:set="SetAsync" />
private bool _isSelected = true;
private Task SetAsync(bool newValue)
{
_isSelected = newValue;
return Task.CompletedTask;
}
Unfortunately, this syntax is not supported by TryMudBlazor, so I can't show a playground.
But yeah, you never want to do this:
valueSwitcher.Value = true;
This is really bad in Blazor. Forget about the imperative way (component.Parameter1 = v1
); only use the declarative syntax (<Component Parameter1="@v1" />
).
from mudblazor.
Related Issues (20)
- `MudTextField` throws exception upon click when `InputType` is set to email & `Mask` is set to `RegexMask.Email()`
- Enable Global Customization of Text Field Variants Across Large Application
- DatePicker IsDateDisabledFunc disables months when FixDay is set
- DatePicker FixYear/FixMonth dialog bug
- MudFileUpload does not fire FilesChanged if one tries to upload the same file again.
- Native html controls have light colors in dark mode HOT 4
- Add ability to control visibility on the MudTreeViewItem HOT 1
- button commit and undo still visible in child table
- MudMenu not closing on CloseMenuAsync HOT 3
- MudSkeleton dark mode color HOT 1
- VS Error: RZ10012: Found markup element with unexpected name 'SomeMudBlazorElement'. If this is intended to be a component, add a @using directive for its namespace. HOT 1
- MudTreeView: Have both `ServerData` and initial hierarchy of items?
- Static DatePicker initially always showing current month
- MudForm Validation attribute not working HOT 3
- MudSelect with multi-selection of Enums shows wrong text value HOT 1
- ValueConverter HOT 2
- `MudIconButton` & `MudToggleIconButton`: Add parameter `FullWidth` to stretch button HOT 2
- MudSlider docs page height issue Firefox
- Scheduler HOT 1
- Minor: MudDialogInstance.SetTitle doesn't explicitly allow null string HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mudblazor.