模板.源索引不随列表变化



有人能帮我解决索引问题吗?MyImage的行。源已添加,但似乎没有更新列表中的图像。文本更新得很好。我如何获得索引从grapingguard [ndx]。ImageA要更新图像吗?

原为格斗守卫[ndx]。ImageAGrapplingGuard [0]然而,我认为我需要指出它应该与[ndx]相关。ImageAI试图移动绑定上下文后的行,但这并没有改变任何东西。我需要在OnButtonClicked部分中包含一些东西吗?

public partial class BGGrappling : ContentPage
{
List<GrapplingGuard> GrapplingGuard { get; set; }
int ndx = 0;
public BGGrappling()
{
InitializeComponent();
GrapplingGuard = new List<GrapplingGuard>
{
new GrapplingGuard
{
TitleText = "Long Guard",
EngText = "Eng Text 1",
ItText = "IT Text 1",
PageNo = "1/4",
ImageA = "HemaSwordFiore.Images.BGGrapple.LongGuard.png"
},
new GrapplingGuard
{
TitleText = "Boar's Tooth",
EngText = "Eng Text 2",
ItText = "IT Text 2",
PageNo = "2/4",
ImageA = "HemaSwordFiore.Images.BGGrapple.BoardsTooth.png"
}
};
//[ndx] not changing image from list
MyImage.Source = ImageSource.FromResource(GrapplingGuard[ndx].ImageA, typeof(BGGrappling).GetTypeInfo().Assembly);
BindingContext = GrapplingGuard[ndx];
}
async void OnButtonClicked(object sender, EventArgs e)
{
ndx++;
if (ndx < GrapplingGuard.Count && ndx <= 3)
{
BindingContext = GrapplingGuard[ndx];
}
else
{
await Navigation.PopAsync();
}
}

我找到了解决方案,我必须在递增部分添加MyImage.Source

async void OnButtonClicked(object sender, EventArgs e)
{
ndx++;
if (ndx < GrapplingGuard.Count && ndx <= 3)
{
BindingContext = GrapplingGuard[ndx];
}
else
{
await Navigation.PopAsync();
}
...
}

最新更新