をいただければ幸いです。だからあなたはそれをビューに追加するべきです。まず、このような別のファイルにビューを作成します。
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="QRManager.Views.QRResult">
<ContentView.Content>
</ContentView.Content>
</ContentView>
今、あなたのメインページにあなたの名前空間のxmlns:local
を使用して、このビューを追加:あなたのコード内で最後に
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:QRManager.Views;assembly=QRManager"
x:Class="QRManager.Views.QRGeneratorPage"
Title="Generator Page">
<ScrollView>
<StackLayout Padding="10">
<StackLayout>
<Entry x:Name="contentEntry" TextColor="Black"
Placeholder="Texto" PlaceholderColor="Silver"
Keyboard="Text" FontSize="18" HorizontalTextAlignment="Start"/>
<Button Text="Generar QR" HorizontalOptions="FillAndExpand" BackgroundColor="#2196F3" TextColor="White" Clicked="Button_Clicked"/>
</StackLayout>
<local:QRResult x:Name="qrResult" />
</StackLayout>
</ScrollView>
</ContentPage>
が背後
ZXingBarcodeImageView
などで、あなたのビューを設定しますこれは:
private void Button_Clicked(object sender, EventArgs e)
{
try
{
if (contentEntry.Text != string.Empty)
{
barcode = new ZXingBarcodeImageView
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
};
barcode.BarcodeFormat = ZXing.BarcodeFormat.QR_CODE;
barcode.BarcodeOptions.Width = 500;
barcode.BarcodeOptions.Height = 500;
barcode.BarcodeValue = contentEntry.Text.Trim();
////////// SEE HERE //////////
qrResult.Content = barcode;
}
else
{
DisplayAlert("Alert", "Introduzca el valor que desea convertir código QR", "OK");
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
DisplayAlert("Alert", "Introduzca el valor que desea convertir código QR", "OK");
}
}
詳細については、を参照してください。
ZXingBarcodeImageViewはImageから継承されているため、Imageそのものです。なぜそれをページに挿入したくないのですか? – Jason
@ジェイソン私はこれをそのままにしておくと、ユーザーがQRコードを生成するたびに、そのバーコードが追加されますが、交換する必要があります。 –
既に持っているImageコントロールをZxIngBarcodeImageViewに置き換えてください。 – Jason