Possible bug when suggestion list bigger than the actual size of the window

2 posts, 0 answers
  1. lnu
    lnu avatar
    19 posts
    Member since:
    Aug 2012

    Posted 27 Nov 2012 Link to this post


    Here is the scenario: one autocomplete and one button(mvvm with mvvmlight). The Button is enabled only(canexecute command) if the SelectedItem property is null. If the list of suggestions expands beyond the window, two behaviors can occur:
    • If the elemet clicked  is over the window, the command is evaluated immediately.
    • If the element clicked is beyond the window(as in the screenshot), the command is not evaluated until the componebt lose focus.

    <Window x:Class="WpfApplication1.TestAutoComplete"
            Title="TestAutoComplete" Height="100" Width="100"
            DataContext="{Binding TestAutoCompleteBinding, Source={StaticResource Locator}}">
            <StackPanel Orientation="Vertical">
                <telerik:RadAutoCompleteBox ItemsSource="{Binding Source,Mode=TwoWay}" AutoCompleteMode="Suggest" SelectionMode="Single" SelectedItem="{Binding SelectedItem,Mode=TwoWay}" DisplayMemberPath="FirstName"/>
                <Button Command="{Binding TestCommand}" Content="test"/>

    public class TestAutoCompleteViewModel : ViewModelBase
         public ObservableCollection<Customer> _source;
         public ObservableCollection<Customer> Source
                 return this._source;
                 this._source = value;
                 this.RaisePropertyChanged(() => this.Source);
         private ICommand _testCommand;
         public ICommand TestCommand
                 return this._testCommand;
         private Customer _selectedItem;
         public Customer SelectedItem
                 return this._selectedItem;
                 this._selectedItem = value;
                 this.RaisePropertyChanged(() => this.SelectedItem);
         /// <summary>
         /// Initializes a new instance of the <see cref="TestAutoCompleteViewModel" /> class.
         /// </summary>
         public TestAutoCompleteViewModel()
             var customers = new List<Customer>();
             customers.Add(new Customer("testLast1", "testFirst1"));
             customers.Add(new Customer("testLast2", "testFirst2"));
             customers.Add(new Customer("testLast3", "testFirst3"));
             customers.Add(new Customer("testLast4", "testFirst4"));
             customers.Add(new Customer("testLast5", "testFirst5"));
             customers.Add(new Customer("testLast6", "testFirst6"));
             this.Source = new ObservableCollection<Customer>(customers);
             this._testCommand = new RelayCommand(() => { }, () =>
                 return this.SelectedItem != null;
  2. Ivo
    Ivo avatar
    390 posts

    Posted 30 Nov 2012 Link to this post


    The RelayCommand you use depends on the CommandManager.RequerySuggested event. For some reason into the scenario you mentioned the RequerySuggested is not fired and the command is not invalidated. We will investigate this strange behavior, but I believe that depending on the RequerySuggested is not something good. I would suggest you to use a DelegateCommand and invalidate it every time when the SelectedItem of your ViewModel changes. Another solution would be to call the CommandManager.InvalidateRequerySuggested method, without changing the RelayCommand to DelegateCommand, but this will try invalidate to invalidate all yours and WPF's commands.

    Kind regards,
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top