Issue
I have created a currency converter app in Xamarin forms in which we have two Image controls that contain the country flags. Now, if the user clicks the swap button, the flags swap each other.
For example, the source of the first image will go to the second image, and vice versa.
<Image Source="usaflag.png" x:Name="Img1"/>
<Image Source="australiaflag.png" x:Name="Img2"/>
<Button Text="SWAP" x:Name="BtnSwap" Clicked="BtnSwap_OnClicked"/>
Here's my XAML Code. I know the we will write the swapping code in the code behind file. I am not using the MVVM style pattern so if you've any code regarding swapping then kindly share it with me.
Solution
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 OnClick()
event 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;
}
Answered By - Asfend
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.