使用 xamarin 的选择器项目源:
我想实现一个简单的选择器 XAML,当我从选择器中选择一个值时,将自动填充(数据来自 firebase)。这是我所拥有的:
view Model xaml:
<Picker HeightRequest="50"
x:Name="AppoiPatientName" Title="Patient Name" FontSize="Large"
SelectedItem="{Binding AppointmentPatientName}"
ItemsSource="{Binding AllAppointment}"
ItemDisplayBinding="{Binding AppointmentPatientName}">
</Picker>
file cs
var picker = new Picker { Title = "Patient Name" };
picker.SetBinding(Picker.ItemsSourceProperty, "AllAppointment");
picker.SetBinding(Picker.SelectedItemProperty, "AppointmentPatientName");
picker.ItemDisplayBinding = new Binding("AppointmentPatientName");
model view :
public void AllAppointment()
{public void AllAppointment()
{
services = new AppintmentService();
Schedules = services.getScheduleAppointment();
}
services = new AppintmentService();
Schedules = services.getScheduleAppointment();
}
services
public ObservableCollection<Appoitment> getScheduleAppointment()
{
var ScheduleData = firebaseClient
.Child("$Specalists / 406707265 / Patients / 0 / Appointments")
.AsObservable<Appoitment>()
.AsObservableCollection();
return ScheduleData;
}
I'd like to implement a simple picker XAML, where when I choose a value from the picker will be populated automatically (the data comes from firebase). Here is what I have:
view Model xaml:
<Picker HeightRequest="50"
x:Name="AppoiPatientName" Title="Patient Name" FontSize="Large"
SelectedItem="{Binding AppointmentPatientName}"
ItemsSource="{Binding AllAppointment}"
ItemDisplayBinding="{Binding AppointmentPatientName}">
</Picker>
file cs
var picker = new Picker { Title = "Patient Name" };
picker.SetBinding(Picker.ItemsSourceProperty, "AllAppointment");
picker.SetBinding(Picker.SelectedItemProperty, "AppointmentPatientName");
picker.ItemDisplayBinding = new Binding("AppointmentPatientName");
model view :
public void AllAppointment()
{public void AllAppointment()
{
services = new AppintmentService();
Schedules = services.getScheduleAppointment();
}
services = new AppintmentService();
Schedules = services.getScheduleAppointment();
}
services
public ObservableCollection<Appoitment> getScheduleAppointment()
{
var ScheduleData = firebaseClient
.Child("$Specalists / 406707265 / Patients / 0 / Appointments")
.AsObservable<Appoitment>()
.AsObservableCollection();
return ScheduleData;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 Jason 所建议的,您应该在 Xaml 或后面的代码中定义 Picker。
更重要的是,
ItemsSource
属性:AllAppointment
应定义为公共属性。此外,您应该考虑使用ObservableCollection
类型,因为这有助于获得通知当有东西被添加到这个集合中时。因此,请使用如下所示的 AllAppointment:
As Jason suggested,you should define the Picker either in Xaml or in code behind.
More importantly,the
ItemsSource
property:AllAppointment
should be defined as public properties.Moreover,you should consider using the typeObservableCollection
as that helps get notified when something was added to this collection.So Use the AllAppointment like below: