Giter Club home page Giter Club logo

Comments (5)

versile2 avatar versile2 commented on September 22, 2024 1

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.

Anu6is avatar Anu6is commented on September 22, 2024

Simply set the Value property to true via a variable - https://try.mudblazor.com/snippet/mamIETbBJdVjwnGH

from mudblazor.

versile2 avatar versile2 commented on September 22, 2024

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.

Anu6is avatar Anu6is commented on September 22, 2024

Great. Feel free to close this issue if you're satisfied.

from mudblazor.

ScarletKuro avatar ScarletKuro commented on September 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.