我想在后台代码更改了ImageSource
值后更新显示在屏幕上的图像。我试过使用INotifyPropertyChnage
,但如果只有我一个人,这似乎不起作用。
public string ImageSource
{
get => _ImageSource;
set
{
if (_ImageSource == value)
return;
_ImageSource = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(ImageSource)));
}
}
这是my GameLoop
方法,用于将
private async Task GameLoop(int maxWordsInCurrentGame)
{
for (int i = 1; i <= maxWordsInCurrentGame; i++)
{
var gameResources = GetSourcesFromConfig(CurrentGame, i, true, true, true, true, true, true, false);
_ImageSource = gameResources["image"];
_MediaSource = gameResources["video"];
await Task.Delay(10000);
}
CurrentGame += 1;
StartGame();
}
我目前只有它等待10秒来改变图像,但它没有发生。
我将DataBinding
用于我的XAML
前端代码
<Image Source="{Binding ImageSource}"
BackgroundColor="White"
Grid.Row="1"
VerticalOptions="Start"
HeightRequest="75"
Margin="0, 20, 0, 0"
Aspect="AspectFill"/>
感谢您提前回答。
1条答案
按热度按时间jljoyd4f1#
因此,您更新的属性是错误的:
您可以像这样编写代码,然后很明显更新“ImageSource”而不是“***_imageSource***"。