WPF AutoCompleteBox

Topics: Conventions
Aug 24, 2012 at 6:04 PM
Edited Aug 24, 2012 at 6:06 PM

I'm trying to set uo the conventions for the AutoCompleteBox from the WPF Toolkit.  From elsewhere, I found this (for the Silverlight version)


   (AutoCompleteBox.ItemsSourceProperty,"SelectedItem", "SelectionChanged")
     .ApplyBinding = (viewModelType, path, property, element, convention) =>
             (element,AutoCompleteBox.SelectedItemProperty, viewModelType, path);

         return true;


Here's my XAML:


<swcit:AutoCompleteBox x:Name="Plays"
  cal:Message.Attach="[Event Populating] = [ReadPlays($eventArgs)]; [SelectPlay]"


And in my view model : 


public BindableCollection<PlayInfo> Plays{ get; set; }
public PlayInfo SelectedPlay { get; set;}�

ReadPlay() reads a web service and fills the Plays collection.

Now, if I remove the ApplyBinding() from the convention setup, the drop-down populates correctly, and SelectPlay() is called upon SelectionChanged but SelectedPlay is never set.  However, if I put the ApplyBinding back, then ReadPlays is never called.
What am I doing wrong?
Aug 28, 2012 at 6:02 PM

After some experimenting, I figured it out.

ConventionManager.AddElementConvention<AutoCompleteBox>(AutoCompleteBox.ItemsSourceProperty, "SelectedItem", "SelectionChanged")
	.ApplyBinding = (viewModelType, path, property, element, convention) =>
			ConventionManager.SetBindingWithoutBindingOverwrite(viewModelType, path, property, element, convention, convention.GetBindableProperty(element));
			ConventionManager.ConfigureSelectedItem(element, AutoCompleteBox.SelectedItemProperty, viewModelType, path);
			return true;

If I include both the standard binding (to handle the ItemsSource), and the SelectedItem binding, it handles both properties correctly.

Feb 24, 2013 at 2:44 PM
Thank you James! This helped me a lot!