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:
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;
});
}
}