Search code examples
c#xamarin.formsstacklayout

StackLayout with Labels acting weird


So I'm coding a Hang Man game. I've done it with WPF already and now trying with Xamarin. In WPF, I figured out a smart way to show the correct guessed letters:

SPLetters: StackLayout with Labels in it (Each label displays one letter from the word to guess | triedLetter: the guessed letter)

So I go through every Label in this StackLayout and I look if the label's content is equal to the triedLetter. If so, I set the label to visible.

Btw. the method to give each label a letter from the word: letters: Char[] with each letter of the word | lblLetter1: each label's name

On Xamarin, this happens:

wordToGuess = test
every Label: ----
triedLetter: t -> StackLayout: Tt--
triedLetter: s -> StackLayout: Tst-
triedLetter: e -> StackLayout: Test

On my wpf project it looked like this:

wordToGuess = test
every label: ----
triedLetter: t -> StackLayout: T--t
triedLetter: s -> StackLayout: T-st
triedLetter: e -> StackLayout: Test

Any idea why? Seems like StackLayouts are acting different from StackPanels on WPF.

And yes, I know there are some questions about the same topic, but they're doing it differently. And before I take someone else's idea, I like to solve my way instead.


Solution

  • Solve :
    Instead of label.IsVisible = true/false, I used label.Opacity = 0/100
    Thanks to Skin for the solution !