Simple Binding Example

Jun 12, 2015 at 7:55 PM
First, this is a really awesome control!

I am a neewbie to mvvm and was wondering if you can please post a small example on how to have this work binding to an observable collection in my view model.

I just can't seem to get it to work and any help would be greatly appreciated.

Thanks again for all your hard work!
Coordinator
Jun 16, 2015 at 4:30 AM
The way I have designed the control, you cannot bind it to ObservableCollection or any IEnumerable. It uses suggestion provider and you can always return your observable collection from GetSuggestions method from suggestion provider.

The source code has a sample application also which you can use to try your scenarios.


Thanks,
Deepak
Jul 11, 2015 at 12:01 AM
Edited Jul 11, 2015 at 12:02 AM
in xaml:
<Window.DataContext>
<viewmodels:mainViewModel/>
</Window.DataContext>
<Grid>
  <wpf:AutoCompleteTextBox MinWidth="200" x:Name="acb" Background="White"
                             Height="25"
                             Margin="2"
                             DisplayMember="name"
                             Watermark="Producent" 
                             SelectedItem="{Binding selectedItem}"
                             IconPlacement="Left"
                             IconVisibility="Visible"
                             Provider="{Binding suggestionProvider}">                      
        <wpf:AutoCompleteTextBox.LoadingContent>
            <TextBlock Text="Loading..."
                       Margin="5"
                       FontSize="14" />
        </wpf:AutoCompleteTextBox.LoadingContent>
        <wpf:AutoCompleteTextBox.Icon>
            <Border Width="20"
                    Height="20">
                <Image Source="Resources/search_icon.png"
                       Height="16"
                       Width="16"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Center" />
            </Border>
        </wpf:AutoCompleteTextBox.Icon>
    </wpf:AutoCompleteTextBox>
</Grid>
and in mainViewModel:
public SuggestionProvider suggestionProvider
    {
        get
        {
            return new SuggestionProvider(x =>
            {
               ObservableCollection<object> collection = new ObservableCollection<object>();
               collection.Add(new item());
                 ...etc

                return collection.Where(o => o.name.Trim().ToUpper().Contains(x.Trim().ToUpper()));
            });
        }
    }
Something like that..
Marked as answer by richcir on 7/21/2015 at 6:01 AM
Jul 21, 2015 at 2:02 PM
Just wanted to say thanks andreas_k!
Jul 21, 2015 at 7:55 PM
Edited Jul 21, 2015 at 7:57 PM
No problem, if You have additional questions, just give me know, I'll try to help You...