Ejemplo n.º 1
0
        private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            // Clear previous entries
            ClearBlocks();
            definitionsComboBox.Items.Clear();

            // Check to see if input is empty or invalid
            if (inputTextBox.Text == null || inputTextBox.Text == "")
            {
                return;
            }

            // Webreqest to UrbanDictionary to find all similar definition entries
            DefinitionList list = Lookup.LookupDefinitions(inputTextBox.Text);

            // Final check to see if the results were null
            if (list == null || list.definitions == null || list.definitions.Count == 0)
            {
                definitionsComboBox.IsEnabled = false;
                return;
            }

            // Add results to the ComboBox
            foreach (Definition def in list.definitions)
            {
                definitionsComboBox.Items.Add(def);
            }

            // Make sure the ComboBox is enabled
            definitionsComboBox.IsEnabled = true;
            // Set the current selected ComboBox option to the most apporopriate
            definitionsComboBox.SelectedValue = DefinitionHandler.FindBestDefinition(list, inputTextBox.Text) ?? definitionsComboBox.Items[0] ?? null;
        }
Ejemplo n.º 2
0
        private void DefinitionsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // Clear definition and example text boxes to be ready to be updated
            ClearBlocks();

            // Get the currently selected item
            Definition updateDef = (Definition)definitionsComboBox.SelectedItem;

            if (updateDef == null)
            {
                return;
            }

            // Update text boxes
            definitionTextBox.AppendText(DefinitionHandler.Format(updateDef.definition));
            exampleTextBox.AppendText(DefinitionHandler.Format(updateDef.example));

            // Update the likes / dislikes
            UpdateLikes(updateDef);
        }