.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,581 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I want to display the Radio button Selection in a Label (example Area/Perimeter),without submitting the button two way binding, please suggest.
@page "/SquareSide"
@using System.ComponentModel.DataAnnotations;
@using MauiAppMCQs.Models;
@using static MauiAppMCQs.Models.ComponentEnums;
<h3>Square Area or Perimeter</h3>
<PageTitle>Square</PageTitle>
<div >
<fieldset disabled=@isdisabled>
<InputRadioGroup @bind-Value="Calulation" >
@foreach (var calculationItem in Enum.GetValues<Calulation>())
{
<div>
<label>
<InputRadio Value="calculationItem" />
@calculationItem
</label>
</div>
}
</InputRadioGroup>
</fieldset>
<fieldset>
<legend>Enter Value </legend>
<InputNumber @bind-Value="num1" disabled=@isdisabled />
<button @onclick="Calculate" disabled=@isdisabled>
Calculate
</button>
</fieldset>
<br >
<p>@calcx</p>
<br >
<fieldset>
<legend>Side</legend>
<div>@Side</div>
</fieldset>
<br>
<button @onclick="Clear" >
Clear
</button>
<br />
@errmsg
</div>
@code {
[Required, EnumDataType(typeof(Calulation))]
public Calulation? Calulation { get; set; } = MauiAppMCQs.Models.ComponentEnums.Calulation.Area; public string skip; public string type;
private bool isdisabled = false; public string errmsg = ""; public string calcx = "";
public class ComponentEnums
{
public enum Calulation { Perimeter, Area }
}
public double Side ;
public double num1 ;
private void Calculate()
{
if (num1 > 0)
{
isdisabled = true;
}
errmsg = "";
skip = "N";
if ((num1 <= 0))
{ skip = "Y"; isdisabled = false; }
if ((num1 > 2000))
{ skip = "Y"; isdisabled = false; }
if (skip == "N")
{
if (Calulation == MauiAppMCQs.Models.ComponentEnums.Calulation.Area)
{ Side = Math.Round(Math.Sqrt(num1), 1); calcx = "Input is Area"; }
else
{
if (Calulation == MauiAppMCQs.Models.ComponentEnums.Calulation.Perimeter)
{
calcx = "Input is Perimeter";
Side = Math.Round((num1 / 4), 1); }
else
{ errmsg = "Check a Radio Button"; }
}
}
else
{ errmsg = "Enter a number between 1 and 2000"; }
}
private void Clear()
{ num1 = 0; isdisabled = false; Side = 0; calcx = ""; }
}
then add a click handlers for the radio buttons. pass the value to the click handler