I have a text file that contains 10 words, only one of them per line. My intention is to call each line, visualize the word in Textbox
and extract each letter of the word and mix it with random letters, the idea is that the user looks at the word and forms it using each button with the corresponding letter, as well as You can see it in the figure.
In this picture you can see, how the buttons are set in xaml
without any specific name, and when the code is executed, the letters are assigned using the function FindVisualChildren
but that only works for the first word of the file.
How can I rerun this function several times?
To locate the letters (those corresponding to the word, and the random ones) inside the buttons I use a function called findvisualChildren
that is responsible for assigning each button the corresponding letter and visualize it as its content.
This is the code:
public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
{
if (depObj != null)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
if (child != null && child is T)
{
yield return (T)child;
}
foreach (T childOfChild in FindVisualChildren<T>(child))
{
yield return childOfChild;
}
}
}
}
The next step is to verify that the word that the user has formed when clicking on the button corresponds to the extracted word, so that when the whole word is formed, a OK
should appear and show the next word in the word file, but when that happens I can not reassign the new letters, because I can not call the function that has already been executed.
I do not know how to make this function run n
times, if when I put it within a while
until it does not meet the condition the result is not seen, therefore I can only see the last word of the file.