Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4267

How to draw in Blazor simple boolean lamp switching depending on variable

$
0
0

I'm trying to draw in Blazor app a lamp as circle which would change the color to green when the state of the boolean variable is activated. Firstly I tried just display a gray circle, but nothing is shown. I'm basing on the project from the site: https://jonhilton.net/blazor-traffic-light/.The code of home.razor looks:

@page "/"@inherits ValveComponent<PageTitle>Home</PageTitle><div class="lamp"><div class="on @(IsOn ? "on" : "off")"></div></div>

I also attached class ValveComponent.razor.cs:

using Microsoft.AspNetCore.Components;namespace GardenHMI{    public class ValveComponent : ComponentBase    {        public bool IsOn { get; set; }        public void Toggle()        {            IsOn = !IsOn;        }    }}

and lamp.css:

.lamp {    padding: 1em;    border: 1px solid grey;    width: 6em;    background-color: #343a40;}.lamp div {    margin-bottom: 0.5em;    border: 2px solid grey;    width: 4em;    height: 4em;    border-radius: 50%;}div.on {    background-color: greenyellow;}

the structure of the project is:

enter image description here

The result while debuggind doesn't display the circle as I wanted. The site is blank:

enter image description here

What am I doing wrong here?


Viewing all articles
Browse latest Browse all 4267

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>