【发布时间】:2020-12-04 10:12:31
【问题描述】:
我是 Xamarin 的新手,我尝试通过新类从 Xaml.Page 更改 Image.Source。也许有人可以帮我解决这个问题。
例如 我有一个 PageX.xaml 和一个 Image x:Name="ImageX" 和一个新的 ClassY
现在我想在 Z 情况发生时将 ImageX.Source 从 PageX 更改。
对我的代码的一些见解:
Xaml:
<Image
x:Name="ImageNonBossAnimation"
BackgroundColor="Transparent"
Grid.Row="18"
Grid.RowSpan="10"
Grid.Column="20"
Grid.ColumnSpan="7"
/>
新类:
public static async void AttackSkills(string pressedSkill, string monsterType)
{
if (pressedSkill == "SkillX")
{
if (monsterType == "nonBoss")
{
for (int animCounter = 1; animCounter <= 6; animCounter++)
{
PageX.ImageNonBossAnimation.Source = "anim_stroke" + animCounter.ToString();
await Task.Delay(30);
}
Page.ImageNonBossAnimation.Source = null;
}
--another occasion takes place here--
}
}
我真的很感激任何帮助。
【问题讨论】:
-
您好,欢迎您。您是否使用 MVVM 概念构建代码,这是 Xamarin 应用程序的首选方法?
-
当 Z 情况发生时你在 PageY 并且你希望 PageX.Image 改变?
-
@ChrisBD 感谢您的回答。我想我没有使用 MVVM 概念。我正在使用普通的 Xamarin ContentPage,您可以在其中获得链接的 .cs。
-
@ShubhamTyagi 我在 PageX 上,正在调用一个新的 classY。我想用 classY 中的函数更改 PageX.Image。希望这能回答你的问题。感谢您的提问。
标签: c# xamarin xamarin.forms xamarin.android