How to swap two images in Xamarin Forms [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last year.
Improve this question
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.

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;
}

In this case, you can Bind the sources and change those values on BtnSwap_OnClicked.

Related

Load More Items at End of ListView in Xamarin.Forms [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I am trying to add more items to at the End of The listview when scrolling, and while doing my research I found this link https://montemagno.com/load-more-items-at-end-of-listview-in/, But when I tried to apply it on my code, I got stuck. I just want to know if someone can help with this. thank you in advance
In my precise I also tried to use this listview that James Montemagno made available, but I did not succeed as well.
I then left for another listview with infinite scroll and it's working for me to this day.
https://github.com/CarlosHSantos/XamarinMarvelApp
I think there might be serveral Issues with your code:
You want your listViewJson.ItemsSource to be a ObservableCollection instead of a normal list. (I assume that it is a normal List, it is not obvious from the code your show)
You maybe want to implement the ItemAppearing in the following way:
ItemAppearing += async (sender, e) =>
if (isLoading || jokeDisplay.value.Count == 0)
return;
//hit bottom!
if (e.Item.ToString() == Items[Items.Count - 1])
{
await LoadItems();
}
};
Lastly, within LoadItems() function, you need to replace Items with
(listViewJson.ItemsSource as ObservableCollection<TypeOfTheItemHere>).Add(ItemToAddHere)
It would be easier if you would have a property within your JokeList class that holds the ObservableCollection, so that you don't have to do all the casting everytime you want to access it.

Visual studio - toggle switch hiding text blocks? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am doing a school project and i canĀ“t figure out how to "hide" some text blocks when the toggle switch is on and the opposite? Developing a windows 8 app. Thanks and btw. How do you make a collection from multiple text blocks(XAML)?
private void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
{
}
Assuming your control structure is fairly flat, you can get by using the Tag property on the TextBox. In your XAML, put some distinct value in the Tag field for each TextBox you want to make toggle-able, like the word 'CanToggle'. Then you can do something like
private void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
{
foreach (Control currentControl in this.Children)
{
if (currentControl.Tag == "CanToggle")
currentControl.Visible = !currentControl.Visible;
}
}
If your control collection is not flat, then you'll have to figure out how to dig recursively through the collection of controls to locate all the TextBox that you want to toggle. This answer may help.
Visual Studio Main Menu - Edit - Outlining - Toggle All Outlining: Ctrl+M, Ctrl+L
Personally, I use Ctrl+M to "collapse to defininitions" more than anything else though.

how do you create a custom table looks like this [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
http://i.stack.imgur.com/Hi9Iz.jpg
i am trying to create a table in c# which should look like at example above and it should be usable in a loop. example: i have two variables called "text" and "author" big box belongs to text and right bottom box belongs to author. those variables available in a loop. what i want to is fill those boxes and make it compatible with loop. i managed to solve this with textboxes but i couldn't figure out how to make them stay under another one.
The easier way (that i am aware of) to do what you want is with an usercontrols and a flowLayoutPanel so we do it as follow
Create an UserControl
create it with panels or textBox in the way you want your table to be, i did like so
Create a flowLayoutPanel
put it where you like it to be and set those properties
this.flowLayoutPanel1.AutoScroll = true;
this.flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
this.flowLayoutPanel1.WrapContents = false;
add as much table like UserControl you want in it the result should be as follow

How to allow only valid values in a combobox? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
in C# with DotNet 4 i have a form with a combobox which is filled with values when starting the program.
Now user can dropdown and select one of the values.
But: It is also possible to write something new into the combobox-field.
Question: What can i do that it is NOT possible to write something which is not part of the list?
Thanks
To make the text portion of a ComboBox non-editable, set the DropDownStyle property to "DropDownList".
It can be done by simply assigning a property to combobox .DropDownStyle = ComboBoxStyle.DropDownList. but, this property do not allow to edit text. means you have to select item either by mouse or by up/down arrow key. You cannot filter result by selecting this property. if you wish to filter result but don't allow to accept invalid value then you can do this by writing some code in cmb_Validating event
private void cmb_Validating(object sender, CancelEventArgs e)
{
if (cmb.SelectedValue == null && cmb.Text != string.Empty)
e.Cancel=true;
}

Why does C# allow creating an object with the same reference? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Here is an example of my code:
Button1_Click(object sender, EventArgs e)
{
PictureBox PB = new PictureBox;
PB.Name = TextBox1.Text;
}
In this code when a user clicks the button, a new object of type PictureBox will be created. Then Name will be assigned the object. How's this possible?
I mean if user clicks again, another object with same reference will be created. How's this possible?
How's this possible?
The Name property on a Control is just a string property - you can assign it anything you want, so having multiple controls with the same name is just the same as having multiple text boxes displaying the same text, or any other class with a string property.
Note that, in your case, you're not actually using or storing the PictureBox you create in any way, so it's going to be eligible for GC as soon as your method ends.

Categories