public class MainPageViewModel : ViewModelBase, INavigationAware
{
public DelegateCommand<object> SelectionChangedCommand { get; set; }
private ObservableCollection<Employee> employeeCollection;
public ObservableCollection<Employee> EmployeeCollection
{
get { return employeeCollection; }
set { employeeCollection = value; }
}
INavigationService _navigationService;
public MainPageViewModel(INavigationService navigationService) : base(navigationService)
{
SelectionChangedCommand = new DelegateCommand<object>(SetContent);
EmployeeCollection = new ObservableCollection<Employee>();
EmployeeCollection.Add(new Employee() { ID = 1, Name = "Frank" });
EmployeeCollection.Add(new Employee() { ID = 2, Name = "James" });
EmployeeCollection.Add(new Employee() { ID = 3, Name = "Steve" });
EmployeeCollection.Add(new Employee() { ID = 4, Name = "Lucas" });
EmployeeCollection.Add(new Employee() { ID = 5, Name = "Mark" });
EmployeeCollection.Add(new Employee() { ID = 6, Name = "Michael" });
EmployeeCollection.Add(new Employee() { ID = 7, Name = "Aldrin" });
EmployeeCollection.Add(new Employee() { ID = 8, Name = "Jack" });
EmployeeCollection.Add(new Employee() { ID = 9, Name = "Howard" });
}
public void SetContent(object obj)
{
}
} |
<combobox:SfComboBox IsEditableMode="True" DataSource="{Binding EmployeeCollection}" MaximumDropDownHeight="300" ShowSuggestionsOnFocus="True" DisplayMemberPath="Name" x:Name="comboBox">
<combobox:SfComboBox.Behaviors>
<local:EventToCommandBehavior Command="{Binding SelectionChangedCommand}" EventName="SelectionChanged"/>
</combobox:SfComboBox.Behaviors>
</combobox:SfComboBox> |
public class MainPageViewModel
{
public ICommand SelectionChangedCommand { get; set; }
private ObservableCollection<Employee> employeeCollection;
public ObservableCollection<Employee> EmployeeCollection
{
get { return employeeCollection; }
set { employeeCollection = value; }
}
public MainPageViewModel()
{
SelectionChangedCommand = new Command<object>(ComboBoxSelectionChanged);
EmployeeCollection = new ObservableCollection<Employee>();
EmployeeCollection.Add(new Employee() { ID = 1, Name = "Frank" });
EmployeeCollection.Add(new Employee() { ID = 2, Name = "James" });
EmployeeCollection.Add(new Employee() { ID = 3, Name = "Steve" });
EmployeeCollection.Add(new Employee() { ID = 4, Name = "Lucas" });
EmployeeCollection.Add(new Employee() { ID = 5, Name = "Mark" });
EmployeeCollection.Add(new Employee() { ID = 6, Name = "Michael" });
EmployeeCollection.Add(new Employee() { ID = 7, Name = "Aldrin" });
EmployeeCollection.Add(new Employee() { ID = 8, Name = "Jack" });
EmployeeCollection.Add(new Employee() { ID = 9, Name = "Howard" });
}
public void ComboBoxSelectionChanged(object obj)
{
var selectionChangedArgs = obj as SelectionChangedEventArgs;
var selectedItem = (selectionChangedArgs.Value as Employee).Name;
}
} |