This is a migrated thread and some comments may be shown as answers.

Doesn't Work with Binding

10 Answers 130 Views
AutocompleteBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Josh
Top achievements
Rank 1
Josh asked on 19 Dec 2011, 06:07 AM
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.

10 Answers, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 20 Dec 2011, 08:44 AM
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 >>

0
Josh
Top achievements
Rank 1
answered on 20 Dec 2011, 03:57 PM
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.
0
Dario
Top achievements
Rank 1
answered on 21 Dec 2011, 11:38 AM
try to add in <phone:PhoneApplicationPage ...
 DataContext="{Binding RelativeSource={RelativeSource Self}}"

is possible that the binding don't know what ot bind.
0
Dario
Top achievements
Rank 1
answered on 21 Dec 2011, 11:45 AM
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

0
Josh
Top achievements
Rank 1
answered on 21 Dec 2011, 04:28 PM
@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.
0
Josh
Top achievements
Rank 1
answered on 21 Dec 2011, 04:31 PM
@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.
0
Josh
Top achievements
Rank 1
answered on 21 Dec 2011, 08:05 PM
I just downloaded the latest realease 2011.3 1221 and the issue still occurs.
0
Deyan
Telerik team
answered on 22 Dec 2011, 12:56 PM
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 >>

0
Josh
Top achievements
Rank 1
answered on 23 Dec 2011, 04:57 AM
Yes, that didn't help. Does the example I gave work for you when you remove that?
0
Accepted
Deyan
Telerik team
answered on 28 Dec 2011, 12:55 PM
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 >>

Tags
AutocompleteBox
Asked by
Josh
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Josh
Top achievements
Rank 1
Dario
Top achievements
Rank 1
Share this question
or