I have created a currency converter app in xamarin forms in which we have two Image controls which contains the country flags. Now when the user will click the swap button then the flag swap each other. For example the source of first image will go to the source of the second image and the source of the second image will go to the source of the first image.
<Image Source="usaflag.png" x:Name="Img1"/>
<Image Source="australiaflag.png" x:Name="Img2"/>
<Button Text="SWAP" x:Name="BtnSwap" Clicked="BtnSwap_OnClicked"/>
CodePudding user response:
Okay so you want to swap two images in xamarin forms. Well that's pretty simple.
You just need to add this code inside the event clicked of a button.
private void BtnSwap_OnClicked(object sender, EventArgs e)
{
var firstImage = Img1.Source;
var secondImage = Img2.Source;
Img2.Source = firstImage;
Img1.Source = secondImage;
}
CodePudding user response:
In this case, you can Bind the sources and change those values on BtnSwap_OnClicked.
