dcsimg
Results 1 to 2 of 2

Thread: [Help needed] WPF Toolkit AutoCompleteBox

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2016
    Posts
    35

    [Help needed] WPF Toolkit AutoCompleteBox

    I've been following the example to make a simple AutoCompleteBox.

    xaml
    Code:
    <Window x:Class="Whatever.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
    Title="Whatever" Height="300" Width="300">
    <Grid>
    <toolkit:AutoCompleteBox x:Name="SearchBox" HorizontalAlignment="Center" Width="200" Height="20"
    ItemsSource="{Binding Names}"
    SelectedItem="{Binding SelectedName, Mode=TwoWay}" />
    </Grid>
    </Window>
    xaml.cs
    Code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    
    namespace Whatever
    {
    public partial class Window1 : Window
    {
    public Window1()
    {
    InitializeComponent();
    DataContext = new ViewModel();
    }
    }
    }
    ViewModel.cs
    Code:
    using System;
    using System.Text;
    using System.Linq;
    using System.Collections.Generic; 
    
    namespace Berg
    {
    public class ViewModel
    {
    IEnumerable<string> Names { get; }
    string SelectedName { get; set; }
    
    public ViewModel()
    {
    }
    
    }
    }
    Now, I know I have to "populate" the red part but I'm lost.
    I'm not a coder nor an advanced user. I'm just trying to do this for my own humble purposes
    Can someone please help a little?
    Last edited by kmlj; Jun 10th, 2019 at 03:35 AM.

  2. #2

    Thread Starter
    Member
    Join Date
    Nov 2016
    Posts
    35

    Re: [Help needed] WPF Toolkit AutoCompleteBox

    ViewModel.cs
    Code:
    using System;
    using System.Text;
    using System.Linq;
    using System.Collections.Generic; 
    
    namespace Berg
    {
    public class ViewModel
    {
    public List<string> Names { get; set; } 
    public ViewModel()
    {
    Names = new List<string>()			
    {
       "John", "Jimmy", "James", "Jim"
    };
    }
    }
    }
    This is working just the way I want it to.
    Nevertheless, still don't know what "string SelectedName { get; set; }" is for ....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width