1
我想經常從內存中更新我的頁面中的圖像。我已經測試了從資源直接(閃爍)和預加載流(閃爍)加載它。這是我的XAML:更新Xamarin中沒有閃爍的圖像
<Image Source="{Binding Image}" VerticalOptions="Center" HorizontalOptions="FillAndExpand"/>
這是我的視圖模型:
this.loaderTask = new Task(() =>
{
int i = 0;
while (true)
{
await Task.Delay(1000);
if (i++ % 2 == 0)
this.Image = ImageSource.FromStream(() => new MemoryStream(this.buf1));
else
this.Image = ImageSource.FromStream(() => new MemoryStream(this.buf2));
Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
{
this.OnPropertyChanged(nameof(this.Image));
});
}
});
測試Android上。我想有一些「標準」的方式來做到這一點?
編輯:通過閃爍我的意思是你很快看到圖像消失,然後繪製新圖像。我希望快速解決方案是將佔位符放在與我想更新的位置相同的位置,但這也沒有幫助,在加載期間仍然獲得默認的白色背景。
上找到一個例子使用動畫在它們之間轉換? – Cheesebaron