Hey everyone,
I was browsing through some programs I wrote for fun, and one such program is an Incremental Search demo that filters through a list of words as characters are entered into an input field. Here are the screenshots of the app in Vista and XP:
I also went ahead and used ClickOnce [tutorial] to create an automatic installer, so those of you on XP/Vista can test it out on your own machines: [URL=“http://www.kirupafx.com/IncrementalSearch/publish.htm”]http://www.kirupafx.com/IncrementalSearch/publish.htm
The source files for this can be accessed from the following location: http://www.kirupa.com/net/code/IncrementalSearch.zip
The XAML code:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xml:lang="en-US"
x:Class="IncrementalSearch.Window1"
x:Name="Window"
Title="Incremental Search"
Width="262" Height="365" Icon=" ext_align_left.png" ResizeMode="NoResize" WindowStyle="SingleBorderWindow">
<Window.Background>
<LinearGradientBrush EndPoint="0.555,1.098" StartPoint="0.274,0.258" SpreadMethod="Pad">
<GradientStop Color="#FFF6F6F8" Offset="0"/>
<GradientStop Color="#FFCADEF6" Offset="0.779"/>
</LinearGradientBrush>
</Window.Background>
<Grid x:Name="LayoutRoot">
<Label Margin="19,3,5,0" x:Name="lblInfo" VerticalAlignment="Top" Height="29" FontSize="14" FontWeight="Normal" Content="Start typing a word below:" Background="#00F4C2C2"/>
<TextBox Margin="20,36,19,0" x:Name="txtInput" VerticalAlignment="Top" Height="23" Background="#BFFFFFFF" BorderThickness="2,2,2,2" Text="" TextWrapping="NoWrap" TextChanged="inputChanged"/>
<ListView Margin="20,76,19,16" x:Name="lstResults" IsSynchronizedWithCurrentItem="True">
<ListView.View>
<GridView>
<GridViewColumn Header="GridViewColumn"/>
</GridView>
</ListView.View>
</ListView>
<Image HorizontalAlignment="Left" Margin="5,10,0,0" VerticalAlignment="Top" Width="16" Height="16" Source="magnifier.png" Stretch="Fill"/>
</Grid>
</Window>
And the C# code is:
using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using System.Collections.Generic;
using System.Resources;
using System.Reflection;
namespace IncrementalSearch
{
public partial class Window1
{
List<string> wordList;
public Window1()
{
this.InitializeComponent();
// Insert code required on object creation below this point.
loadText();
setupColumn();
}
private void inputChanged(object sender, TextChangedEventArgs e)
{
string searchString = txtInput.Text.ToLower();
lstResults.Items.Clear();
foreach (string currentWord in wordList)
{
if (currentWord.IndexOf(searchString) != -1)
{
displayWord(currentWord);
}
}
}
private void displayWord(string wordToAdd)
{
lstResults.Items.Add(wordToAdd);
}
private void loadText()
{
TextReader tr = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("IncrementalSearch.words.txt"));
string currentLine = tr.ReadLine();
wordList = new List<string>();
while (currentLine != null)
{
wordList.Add(currentLine.ToLower());
displayWord(currentLine.ToLower());
currentLine = tr.ReadLine();
}
}
private void setupColumn()
{
GridViewColumn column = (lstResults.View as GridView).Columns[0];
column.Header = "Results";
column.Width = 150;
}
}
}
For the XAML, I used Expression Blend, and for the C#, I used Visual Studio with the [URL=“http://www.microsoft.com/downloads/details.aspx?familyid=F54F5537-CC86-4BF5-AE44-F5A1E805680D&displaylang=en”]WPF Extensions. The WPF Extensions are required if you want to open the entire project in Visual Studio.
If there are any questions, feel free to ask!
Cheers!
Kirupa