Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
XML
<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
C#
public MainPage()
        {
            InitializeComponent();
            Functions.GenerateKeywords();

            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            // Check if ExtendedSplashscreen.xaml is on the backstack  and remove
            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
Posted
Updated 12-May-15 0:28am
v2
Comments
José Amílcar Casimiro 12-May-15 11:07am    
what is your initial approach to solve the problem?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900