Der Benutzer klickt auf ein Formularfeld (fluentTextinput), um einen numerischen Wert einzugeben. OK , um den Wert zu verwenden oder den Vorgang abzubrechen.
Code: Select all
@implements IDialogContentComponent
1
2
3
4
5
6
7
8
9
Clear
0
Backspace
@code {
[Parameter]
public string Content { get; set; } = string.Empty;
public void AddDigit(MouseEventArgs e, int digit)
{
Content += digit.ToString();
StateHasChanged();
}
public void ClearInput()
{
Content = string.Empty;
}
public void Backspace()
{
if (Content.Length > 0)
{
Content = Content.Substring(0, Content.Length - 1);
}
}
}
< /code>
Hier ist der Code für die Hostkomponente, die das Panel für die Eingabe öffnet: < /p>
@code {
private IDialogReference? _dialog;
private string RealPowerCmd { get; set; } = "0";
private async Task OpenDialogRealPower()
{
var parameters = new DialogParameters()
{
Content = RealPowerCmd,
Alignment = HorizontalAlignment.Right,
PrimaryAction = "OK",
SecondaryAction = "Cancel"
};
_dialog = await DialogService.ShowPanelAsync(RealPowerCmd, parameters);
DialogResult result = await _dialog.Result;
if (result.Cancelled)
{
return;
}
if (result.Data is not null)
{
var inputValue = result.Data as string;
RealPowerCmd = inputValue!;
StateHasChanged();
}
}
}
< /code>
inputValue