
QRCode
Generate QR code
Basic usage
Click the Generate button to generate a QRCode
Demo
<QRCode OnGenerated="@OnGenerated" ShowButtons="true"><QRCode>
Direct build
Specify the contents of the QR code with the Content
parameter
Demo
<QRCode Content="https://www.blazor.zone"><QRCode>
Attributes
Loading...
@page "/qrcodes"
<h3>@Title</h3>
<h4>@SubTitle</h4>
<DemoBlock Title="@BaseUsageText" Introduction="@IntroText1" Name="Normal">
<QRCode OnGenerated="@OnGenerated" ShowButtons="true"></QRCode>
<BlockLogger @ref="Trace" class="mt-3" />
<Pre class="mt-3"><QRCode OnGenerated="@OnGenerated" ShowButtons="true"><QRCode></Pre>
</DemoBlock>
<DemoBlock Title="Direct build" Introduction="Specify the contents of the QR code with the <code>Content</code> parameter" Name="Direct">
<QRCode Content="https://www.blazor.zone"></QRCode>
<Pre class="mt-3"><QRCode Content="https://www.blazor.zone"><QRCode></Pre>
</DemoBlock>
<AttributeTable Items="@GetAttributes()" />
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/
using BootstrapBlazor.Shared.Common;
using BootstrapBlazor.Shared.Components;
using Microsoft.Extensions.Localization;
using Microsoft.AspNetCore.Components;
namespace BootstrapBlazor.Shared.Samples;
/// <summary>
///
/// </summary>
public sealed partial class QRCodes
{
[NotNull]
private string? Title { get; set; }
[NotNull]
private string? SubTitle { get; set; }
[NotNull]
private string? BaseUsageText { get; set; }
[NotNull]
private string? IntroText1 { get; set; }
[NotNull]
private string? SuccessText { get; set; }
[NotNull]
private string? CallbackDescription { get; set; }
[Inject]
[NotNull]
private IStringLocalizer<QRCodes>? Localizer { get; set; }
private BlockLogger? Trace { get; set; }
/// <summary>
/// OnInitialized 方法
/// </summary>
protected override void OnInitialized()
{
base.OnInitialized();
Title ??= Localizer[nameof(Title)];
SubTitle ??= Localizer[nameof(SubTitle)];
BaseUsageText ??= Localizer[nameof(BaseUsageText)];
IntroText1 ??= Localizer[nameof(IntroText1)];
SuccessText ??= Localizer[nameof(SuccessText)];
CallbackDescription ??= Localizer[nameof(CallbackDescription)];
}
private Task OnGenerated()
{
Trace?.Log(SuccessText);
return Task.CompletedTask;
}
/// <summary>
/// 获得属性方法
/// </summary>
/// <returns></returns>
private IEnumerable<AttributeItem> GetAttributes() => new AttributeItem[]
{
// TODO: 移动到数据库中
new AttributeItem() {
Name = "OnGenerated",
Description = CallbackDescription,
Type = "Func<Task>",
ValueList = " — ",
DefaultValue = " — "
}
};
}