【发布时间】:2017-04-20 01:52:53
【问题描述】:
我正在 Xamarin Forms 中编写一个 QR 码应用程序,该应用程序在文本条目中获取输入字符串并将其转换为 QR 码。我希望二维码在您输入或删除文本条目时动态更改,类似于我找到的这个网站here。
我相信使用TextChangeEventArgs 可以做到这一点,但我不确定它是如何工作的。我在这里错过了什么?
我的文字输入
var myEntry = new Entry
{
Text = "Hello SO"
};
这是我在更改My Entry 时创建新条形码的函数(它还没有被任何东西调用)
void MyEntryChanged(Entry myEntry, TextChangedEventArgs e)
{
barcode = new ZXingBarcodeImageView
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
AutomationId = "zxingBarcodeImageView",
};
barcode.BarcodeFormat = ZXing.BarcodeFormat.QR_CODE;
barcode.BarcodeOptions.Width = 300;
barcode.BarcodeOptions.Height = 300;
barcode.BarcodeOptions.Margin = 10;
barcode.BarcodeValue = myEntry.Text;
Content = barcode;
}
【问题讨论】:
-
更新UI时可能需要使用Device.BeginInvokeOnMainThread
标签: c# xamarin xamarin.forms qr-code