<StackLayout Padding="30">
<syncPicker:SfPicker HeaderText="Select Item"
DisplayMemberPath="Name"
ShowFooter="True"
PickerHeight="350"
PickerWidth="350"
PickerMode="Default"
ShowHeader="True">
<syncPicker:SfPicker.ItemsSource>
<collection:ObservableCollection x:TypeArguments="local:EmployeeInfo">
<local:EmployeeInfo Name="EUR" ID="1"/>
<local:EmployeeInfo Name="USD" ID="2"/>
<local:EmployeeInfo Name="GBP" ID="3"/>
</collection:ObservableCollection>
</syncPicker:SfPicker.ItemsSource>
</syncPicker:SfPicker>
</StackLayout> |
XAML:
<syncPicker:SfPicker.Behaviors>
<prism:EventToCommandBehavior Command="{Binding SelectionChanged}"
EventName="SelectionChanged"
EventArgsConverter="{StaticResource SelectionChangedConverter}"
/>
</syncPicker:SfPicker.Behaviors>
ViewModel.cs:
public ICommand SelectionChanged { get; set; }
public ViewModel()
{
this.SelectionChanged = new Command(this.OnSelectionChanged);
}
private void OnSelectionChanged(object obj)
{
var id = (obj as EmployeeInfo).ID;
Application.Current.MainPage.DisplayAlert("Notification", "ID " + id, "Ok");
} |
public MainPage()
{
InitializeComponent();
viewmodel = new ViewModel();
var item = new EmployeeInfo() { ID = "3", Name = "GBP" };
picker.SelectedItem = pickerCollection.Where(p => p.ID == item.ID).First();
this.BindingContext = viewmodel;
} |
<syncPicker:SfPicker x:Name="picker"
HeaderText="Select Item"
DisplayMemberPath="Name"
ShowFooter="True"
SelectedIndex="1"
PickerHeight="350"
PickerWidth="350"
PickerMode="Default"
ShowHeader="True"> |
Hi Murat,Thanks for your update.We have validated your query, you can set the SelectedItem of SfPicker using below code snippet.Code snippet:
public MainPage(){InitializeComponent();viewmodel = new ViewModel();var item = new EmployeeInfo() { ID = "3", Name = "GBP" };picker.SelectedItem = pickerCollection.Where(p => p.ID == item.ID).First();this.BindingContext = viewmodel;}Or you can use the SelectedIndex for display the selected item like below code Snippet
<syncPicker:SfPicker x:Name="picker"HeaderText="Select Item"DisplayMemberPath="Name"ShowFooter="True"SelectedIndex="1"PickerHeight="350"PickerWidth="350"PickerMode="Default"ShowHeader="True">We have modified the already provided sample, please get it from below link.Thanks,Muneesh Kumar G
var item= new ModelItemCombobox() { Key = 1, Value = "Submited" };
// In this, you can get the item from the items collection based on your column name and set item to selected item.
viewModel.SelectedItems = viewModel.Items.Where(p => p.Value == item.Value).First();
picker.SetBinding(SfPicker.SelectedItemProperty,"SelectedItems",BindingMode.TwoWay);
|