0

I am downloading an xml file and saving it to the phone (Windows Phone 8 app), then I open it as a list. This list has greek words in it with upper, lower and special characters. I want the user to be able to search thru this list without making him write the same text as is in the list, so, so far I made the search bar and the list to turn into Upper characters so if the user types "to" the list highlights "to","To","TO" erasing temporarily the words not matching bringing up the ones matching. But if the user tries to write a letter without intonation the words in the list that have intonation will all be erased until the user presses backspace and type the letter with intonation.

example: list got 2 words. Σπύρος , Μάρα. User presses letter 'Μ', in the list, Σπύρος disappears and Μάρα becomes Μάρα. Now the user types 'α' and Mάρα disappears as well because he had to type 'ά'. If he had it would be Μάρα and so on.

So my question is, is it possible to replace a character with intonation to the same character without intonation? For example. ά to a, Ά to A, etc. On the Unicode character table they have different codes.

The code so far:

  private void businessFilterString_TextChanged(object sender, TextChangedEventArgs e)
    {
        sI.ItemsSource = businesses.Collection.Where(b => b.name.ToUpper().Contains(searchBox.Text.ToUpper()) || b.address.ToUpper().Contains(searchBox.Text.ToUpper())).ToList();
        LayoutUpdateFlag = true;
    }

    private void sI_LayoutUpdated(object sender, EventArgs e)
    {
        if (LayoutUpdateFlag)
        {
           SearchVisualTree(sI);
        }
        LayoutUpdateFlag = false;
    }
    private void SearchVisualTree(DependencyObject targetElement)
    {

        var count = VisualTreeHelper.GetChildrenCount(targetElement);

        for (int i = 0; i < count; i++)
        {
            var child = VisualTreeHelper.GetChild(targetElement, i);
            if (child is TextBlock)
            {
                textBlock1 = (TextBlock)child;
                prevText = textBlock1.Text.ToUpper();
                HighlightText();
            }
            else
            {
                SearchVisualTree(child);
            }
        }
    }

  private void HighlightText()
  {
      if (textBlock1 != null)
      {
          string text = textBlock1.Text.ToUpper();
          textBlock1.Text = text;
          textBlock1.Inlines.Clear();

          int index = text.IndexOf(searchBox.Text.ToUpper());
          int lenth = searchBox.Text.Length;


          if (!(index < 0))
          {
              Run run = new Run() { Text = text.Substring(index, lenth), FontWeight = FontWeights.ExtraBold};
              run.Foreground = new SolidColorBrush(Colors.Orange);
              textBlock1.Inlines.Add(new Run() { Text = text.Substring(0, index), FontWeight = FontWeights.Normal});
              textBlock1.Inlines.Add(run);
              textBlock1.Inlines.Add(new Run() { Text = text.Substring(index + lenth), FontWeight = FontWeights.Normal });
          }
          else
          {
              //textBlock1.Text = "No Match";
          }
      }
  }
Spyros_Spy
  • 171
  • 15

1 Answers1

0

So I added

  private static string DeleteAccentAndSpecialsChar(string OriginalText)
    {
        string strTemp = OriginalText;

        Regex rega = new Regex("[Ά]");
        Regex rege = new Regex("[Έ]");
        Regex regi = new Regex("[Ί]");
        Regex regu = new Regex("[Ύ]");
        Regex regh = new Regex("[Ή]");
        Regex rego = new Regex("[Ό]");
        Regex regw = new Regex("[Ώ]");

        strTemp = rega.Replace(strTemp, "Α");
        strTemp = rege.Replace(strTemp, "Ε");
        strTemp = regi.Replace(strTemp, "Ι");
        strTemp = regu.Replace(strTemp, "Υ");
        strTemp = regh.Replace(strTemp, "Η");
        strTemp = rego.Replace(strTemp, "Ο");
        strTemp = regw.Replace(strTemp, "Ω");

        return strTemp;
    }

and changed

   private void businessFilterString_TextChanged(object sender, TextChangedEventArgs e)
{
    sI.ItemsSource = businesses.Collection.Where(b => b.name.ToUpper().Contains(searchBox.Text.ToUpper()) || b.address.ToUpper().Contains(searchBox.Text.ToUpper())).ToList();
    LayoutUpdateFlag = true;
}

to

  private void businessFilterString_TextChanged(object sender, TextChangedEventArgs e)
    {
        sI.ItemsSource = businesses.Collection.Where(b => DeleteAccentAndSpecialsChar(b.name.ToUpper()).Contains(DeleteAccentAndSpecialsChar(searchBox.Text.ToUpper()))).ToList();
        LayoutUpdateFlag = true;
    }

This way all text is shown on upper and the intonation is vanished. Still if the user uses intonation on his text, nothing will be displayed tho but suits me well since intonation is not required on upper text.

Spyros_Spy
  • 171
  • 15