I have implemented a search feature in my app that is working fine. see the code below
But i want to do more with the search feature
xaml
<stackpanel>
<textbox name="txtSearch" horizontalalignment="Left" height="72" margin="1,10,0,0" textwrapping="Wrap" verticalalignment="Top" width="355" />
<Button Content="Search" HorizontalAlignment="Right" Margin="1,-75,0,0" VerticalAlignment="Top" Background="#27394d" Click="Search_click"/>
<textblock fontsize="20" foreground="Black" textwrapping="Wrap">Enter keywords you would love to search in the hymn e.g Hymn 1</textblock>
</stackpanel>
xaml.cs
public MainPage()
{
InitializeComponent();
Functions.GenerateKeywords();
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (NavigationService.BackStack.Count() == 1)
{
NavigationService.RemoveBackEntry();
}
}
private void Search_click(object sender, RoutedEventArgs e)
{
string keyword = txtSearch.Text;
Uri url = Functions.GetPageUrl(keyword);
if (url != null)
{
NavigationService.Navigate(url);
}
else
{
MessageBox.Show("Invalid Keyword");
}
}
public class Functions
{
static Dictionary<string,> mKeywords = new Dictionary<string,>();
public static Uri GetPageUrl(string keyword)
{
if (mKeywords.ContainsKey(keyword) == true)
{
return mKeywords[keyword];
}
else
{
return null;
}
}
public static void GenerateKeywords()
{
mKeywords.Add("Hymn 1", new Uri("/Hymn1.xaml", UriKind.Relative));
mKeywords.Add("Hymn 2", new Uri("/Hymn2.xaml", UriKind.Relative));
mKeywords.Add("Hymn 3", new Uri("/Hymn3.xaml", UriKind.Relative));
mKeywords.Add("Hymn 4", new Uri("/Hymn4.xaml", UriKind.Relative));
mKeywords.Add("Hymn 5", new Uri("/Hymn5.xaml", UriKind.Relative));
mKeywords.Add("Hymn 6", new Uri("/Hymn6.xaml", UriKind.Relative));
mKeywords.Add("Hymn 7", new Uri("/Hymn7.xaml", UriKind.Relative));
mKeywords.Add("Hymn 8", new Uri("/Hymn8.xaml", UriKind.Relative));
mKeywords.Add("Hymn 9", new Uri("/Hymn9.xaml", UriKind.Relative));
mKeywords.Add("Hymn 10", new Uri("/Hymn10.xaml", UriKind.Relative));
mKeywords.Add("Hymn 11", new Uri("/Hymn11.xaml", UriKind.Relative));
mKeywords.Add("Hymn 12", new Uri("/Hymn12.xaml", UriKind.Relative));
mKeywords.Add("Hymn 13", new Uri("/Hymn13.xaml", UriKind.Relative));
mKeywords.Add("Hymn 14", new Uri("/Hymn14.xaml", UriKind.Relative));
}
1. I will like to add different text files with set of topics in app folder in which
when a user types in a particular topic/keyword in the search field it will search
for that topic in the text files and display it in a xaml page.
NB:The essence of this is that i dont want to hard code the topics in xaml there by creating
numerous xaml pages in my app
2. I will like the search to have an auto complete feature inclusive
Kindly help and thank you in advance