Doesn't Work with Binding

11 posts, 1 answers
  1. Josh
    Josh avatar
    22 posts
    Member since:
    Jun 2012

    Posted 19 Dec 2011 Link to this post

    I'm having some issues with the RadAutoComplete. It doesn't seem to work all the time when binding. I have a really simple case here that I can demonstrate with.

    I have an ItemsControl above the auto complete to show that the results are actually there and working.

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <StackPanel>
            <ItemsControl ItemsSource="{Binding Items}"/>
            <telerikInput:RadAutoCompleteBox
                x:Name="autoComplete"
                AutoCompleteMode="Contains"
                AutoCompletePopupDisplayMode="AboveTextBox"
                StringComparisonMode="CurrentCultureIgnoreCase"
                SuggestionsSource="{Binding Items}"/>
        </StackPanel>
    </Grid>

    public partial class MainPage : PhoneApplicationPage
    {
        private ObservableCollection<string> items = new ObservableCollection<string>();
     
        public ObservableCollection<string> Items
        {
            get { return items; }
        }
     
        // Constructor
        public MainPage()
        {
            InitializeComponent();
     
            DataContext = this;
        }
     
        protected override void OnNavigatedTo( System.Windows.Navigation.NavigationEventArgs e )
        {
            items.Clear();
            for( var i = 0; i < 10; i++ )
            {
                items.Add( string.Format( "test{0}", i ) );
            }
        }

    What am I doing wrong? I'm using the control in one place in my code and it works fine. I'm doing nearly the exact same thing on another page and it doesn't work.
  2. Deyan
    Admin
    Deyan avatar
    2037 posts

    Posted 20 Dec 2011 Link to this post

    Hi Josh,

    Thanks for writing and for the provided code snippet.

    As far as I can understand your scenario, you are using a collection defined in your DataContext to populate both the RadAutoCompleteBox' suggestions source, as well as an ItemsControl on your page. This, however, will not in any way filter this collection so that filtered items are displayed in your ItemsControl. You should bind the ItemsControl to the FilteredSuggestions property of RadAutoCompleteBox to achieve this scenario.

    Since, however, I am not quite sure that I correctly understand your goal, could you please share some further details so that I can make sure that I provide the right assistance.

    Thanks for your time.

    Best wishes,
    Deyan
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Josh
    Josh avatar
    22 posts
    Member since:
    Jun 2012

    Posted 20 Dec 2011 Link to this post

    The ItemsControl is just there to show that the results should populate. You can complete remove the ItemsControl for this example.

    The issue is, the AutoCompleteBox doesn't pop up the auto complete list when typing. If you type t, nothing happens. Nothing for te... all way through test. The suggestions never appear.
  5. Dario
    Dario avatar
    11 posts
    Member since:
    Oct 2012

    Posted 21 Dec 2011 Link to this post

    try to add in <phone:PhoneApplicationPage ...
     DataContext="{Binding RelativeSource={RelativeSource Self}}"

    is possible that the binding don't know what ot bind.
  6. Dario
    Dario avatar
    11 posts
    Member since:
    Oct 2012

    Posted 21 Dec 2011 Link to this post

    and try to add INotifyPropertyChanged like this

    public partial class MainPage : PhoneApplicationPage, INotifyPropertyChanged
        {
            #region INotifyPropertyChanged Members
            public event PropertyChangedEventHandler PropertyChanged;
            public void OnPropertyChanged(string propertyName)
            {
                PropertyChangedEventHandler handler = PropertyChanged;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
                }
            }
            #endregion
        private ObservableCollection<string> items = new ObservableCollection<string>();
      
        public ObservableCollection<string> Items
        {
            get { return items; }
    set
                {
                    if (items != value)
                    {
                        items = value;
                        this.Dispatcher.BeginInvoke(() =>
                        {
                            OnPropertyChanged("Items");
                        });
                    }
                }
        }
     
     
    ........

    otherwise, when you change the object did not bind

  7. Josh
    Josh avatar
    22 posts
    Member since:
    Jun 2012

    Posted 21 Dec 2011 Link to this post

    @Dario

    The ItemsControl has the data populated just fine, so it should know what to bind. Meaning, I put an ItemsControl on the page also with the same binding to show that it should be binding.
  8. Josh
    Josh avatar
    22 posts
    Member since:
    Jun 2012

    Posted 21 Dec 2011 Link to this post

    @Dario

    An ObservableCollection has a CollectionChanged event on it that is fired when the collection changes. Any control that you can bind a collection to will be looking for this and will update itself when a change occurs. Firing the PropertyChanged event on an ObservableCollection doesn't do anything.
  9. Josh
    Josh avatar
    22 posts
    Member since:
    Jun 2012

    Posted 21 Dec 2011 Link to this post

    I just downloaded the latest realease 2011.3 1221 and the issue still occurs.
  10. Deyan
    Admin
    Deyan avatar
    2037 posts

    Posted 22 Dec 2011 Link to this post

    Hello Josh,

    Could you please try removing the following line from your XAML code and let me know if it fixes the issue for you:

    AutoCompletePopupDisplayMode="AboveTextBox"

    Thanks for your time!

    Greetings,
    Deyan
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  11. Josh
    Josh avatar
    22 posts
    Member since:
    Jun 2012

    Posted 22 Dec 2011 Link to this post

    Yes, that didn't help. Does the example I gave work for you when you remove that?
  12. Answer
    Deyan
    Admin
    Deyan avatar
    2037 posts

    Posted 28 Dec 2011 Link to this post

    Hi Josh,

    As my colleague Todor reported, the issue is identified and will be fixed in our next official release. We are also going to release an Internal Build  containing the fix in the beginning of January.

    Please refer to the support ticket you have opened regarding the same case for any further discussions.

    We will consider this thread closed.

    Thanks for your time.

    Regards,
    Deyan
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
DevCraft banner