使用 xamarin 的选择器项目源:

发布于 2025-01-20 08:56:57 字数 1461 浏览 3 评论 0原文

我想实现一个简单的选择器 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若水微香 2025-01-27 08:56:57

正如 Jason 所建议的,您应该在 Xaml 或后面的代码中定义 Picker。

更重要的是,ItemsSource 属性:AllAppointment 应定义为公共属性。此外,您应该考虑使用 ObservableCollection 类型,因为这有助于获得通知当有东西被添加到这个集合中时。

因此,请使用如下所示的 AllAppointment:

public ObservableCollection<AllAppointmentModel> AllAppointment { get; set; } 
= new ObservableCollection<AllAppointmentModel>();

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 type ObservableCollection as that helps get notified when something was added to this collection.

So Use the AllAppointment like below:

public ObservableCollection<AllAppointmentModel> AllAppointment { get; set; } 
= new ObservableCollection<AllAppointmentModel>();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文