In Xamrain forms how does one make the value default in the picker I have a list which is of type team.
public AddASessionPage(Session session)
{
InitializeComponent();
api = new TheHockeyLabMnHttpApi();
Session = session;
BindPicker();
if (session != null)
{
txtName.Text = session.Name;
var item = pickTeam.SelectedItem as Team;
pickTeam.SelectedItem = item.Name;
txtDateStartEntry.Text = session.StartDate.ToString();
txtDateStartEntry.Text = session.EndDate.ToString();
}
}
My List is made of
public class Team
{
public int Id { get; set; }
public string Name { get; set; }
public int? SessionId { get; set; }
}
My question is on my AddASession Page constructor How do I pic the default Yes I no could use selectedIndex but that is not how am storing am storing based on the text value in the picker.
As such
<Picker x:Name="pickTeam" ItemDisplayBinding="{Binding Name}"></Picker>
Or is their another value I can save get the value of Team > Id in the xaml of the control usually asp.net has a ItemDisplayValue does xamrain have such the same?
CodePudding user response:
assuming that your Picker
ItemSource
is myData
var item = myData.Where(x => x.Name == session.Name).FirstOrDefault();
pickTeam.SelectedItem = item;