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

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

1 Answer 70 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
lnu
Top achievements
Rank 1
lnu asked on 27 Nov 2012, 01:36 PM
Hello,

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"
         xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        Title="TestAutoComplete" Height="100" Width="100"
        DataContext="{Binding TestAutoCompleteBinding, Source={StaticResource Locator}}">
    <Grid>
        <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"/>
        </StackPanel>
    </Grid>
</Window>


public class TestAutoCompleteViewModel : ViewModelBase
 {
     public ObservableCollection<Customer> _source;
 
     public ObservableCollection<Customer> Source
     {
         get
         {
             return this._source;
         }
         set
         {
             this._source = value;
             this.RaisePropertyChanged(() => this.Source);
         }
     }
 
     private ICommand _testCommand;
 
     public ICommand TestCommand
     {
         get
         {
             return this._testCommand;
         }
     }
 
     private Customer _selectedItem;
 
     public Customer SelectedItem
     {
         get
         {
             return this._selectedItem;
         }
         set
         {
             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;
         });
     }
 }

1 Answer, 1 is accepted

Sort by
0
Ivo
Telerik team
answered on 30 Nov 2012, 04:54 PM
Hi,

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,
Ivo
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
AutoCompleteBox
Asked by
lnu
Top achievements
Rank 1
Answers by
Ivo
Telerik team
Share this question
or