我想在每次触发特定的TextChanged 事件时重新绘制QR代码。
当页面加载XAML文件中设置的值BarcodeValue时,将在视图中绘制BarcodeValue对象,如下所示:
<forms:ZXingBarcodeImageView
Margin="5,5,5,0"
x:Name="QRCodeView"
BarcodeFormat="QR_CODE"
BarcodeValue="-1" //this is the value of the QR code
/>我有一个Entry,它附带了一个TextChanged事件,它触发了一个函数UpdateQRLabel。这个函数应该用QRCode中的新值重新绘制Entry
<Entry
x:Name="Message"
TextChanged="UpdateQRLabel"
/>如果在绘制BarcodeValue后更改QRCode参数,则不会自动重新绘制。
每次触发ZXingBarcodeImageView事件时,我都需要强制TextChanged对象重新绘制。
问题
如何在触发ZXingBarcodeImageView事件时强制TextChanged重绘?
发布于 2018-07-10 08:50:51
我不确定你是不是在使用数据绑定。但是,由于您使用的是事件,所以我确实让它使用了数据绑定。在这里可以找到一个样本回购:https://github.com/jfversluis/ZXingValueBinding
说到底就是这样。创建一个保存条形码值的属性:
private string _barcodeValue = "-1";
public string BarcodeValue
{
get { return _barcodeValue; }
set
{
_barcodeValue = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(BarcodeValue)));
}
}持有此属性的对象需要实现INotifyPropertyChanged接口。您可以考虑使用PropertyChanged.Fody来实现这些功能。
我已经把这个属性放在我的页面的代码后面,这也可以是一个单独的类。现在,将条形码图像视图更改为:<forms:ZXingBarcodeImageView ... BarcodeValue="{Binding BarcodeValue}">。
每当您将新值设置为BarcodeValue时,值都会更改,因为UI是由于INotifyPropertyChanged机制而被通知的。
https://stackoverflow.com/questions/51257854
复制相似问题