To implement the display of relevant record by inputing value , you can use AutoCompleteBox.Here is my steps to do it.
Step 1: Search and install DotNetProjects.Input.Toolkit in your project Nuget Package
Step 2: Add xmlns:tookit="clr-namespace:System.Windows.Controls;assembly=DotNetProjects.Input.Toolkit" to import the dll
Step 3: The code for xaml:
<Grid>
<tookit:AutoCompleteBox x:Name="searchTextBox" ValueMemberPath="SerchString" Margin="10" FontSize="20" Height="50" Foreground="Black">
<tookit:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<TextBlock Margin="5,5" FontSize="26">
<Run Text="{Binding SerchString}" Foreground="Blue"/>
<Run Text="{Binding Name}" Foreground="Gray"/>
</TextBlock>
</DataTemplate>
</tookit:AutoCompleteBox.ItemTemplate>
</tookit:AutoCompleteBox>
</Grid>
Step 4: Code for cs:
public MainWindow()
{
InitializeComponent();
this.searchTextBox.Populating += new PopulatingEventHandler(AutoCompleteBox_Populating);
}
private void AutoCompleteBox_Populating(object sender, PopulatingEventArgs e)
{
e.Cancel = true;
List<AutoCompleteModel> data = new List<AutoCompleteModel>();
for (int i = 0; i < 10; i++)
{
AutoCompleteModel model = new AutoCompleteModel();
Random radom = new Random();
model.SerchString = radom.Next(1,30).ToString();
model.Name = "TestName" + i;
data.Add(model);
}
this.searchTextBox.ItemsSource = data;
this.searchTextBox.FilterMode = AutoCompleteFilterMode.Contains;
this.searchTextBox.PopulateComplete();
}
The code for AutoCompleteModel:
public class AutoCompleteModel : INotifyPropertyChanged
{
public void OnPropertyChanged(string propname)
{
if (this.PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propname));
}
}
public event PropertyChangedEventHandler PropertyChanged;
private string searchString = string.Empty;
private string name = string.Empty;
public string SerchString
{
get { return searchString; }
set
{
searchString = value;
this.OnPropertyChanged("SerchString");
}
}
public string Name
{
get { return name; }
set
{
name = value;
this.OnPropertyChanged("Name");
}
}
}
Step 5: The result is like below shown:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.