-
-
Save pskyv/978811e35ff898f4cfb490275c603c7c to your computer and use it in GitHub Desktop.
XfxComboBox sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" | |
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | |
xmlns:material="clr-namespace:SuaveControls.MaterialForms;assembly=SuaveControls.MaterialForms" | |
xmlns:xfx="clr-namespace:Xfx;assembly=Xfx.Controls" | |
xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms" | |
prism:ViewModelLocator.AutowireViewModel="True" | |
x:Class="DentalAssistantXF.Views.EditAppointmentPage" | |
Title="{Binding Title}"> | |
<ContentPage.ToolbarItems> | |
<ToolbarItem Icon="ic_check_white_24dp" Command="{Binding SaveAppointmentCommand}" /> | |
</ContentPage.ToolbarItems> | |
<StackLayout> | |
<StackLayout Style="{StaticResource Strip}"> | |
<Label Text="Appointment information" /> | |
</StackLayout> | |
<StackLayout Padding="15,0"> | |
<xfx:XfxComboBox Placeholder="Search for a patient..." | |
Threshold="3" | |
Text="{Binding FilterText, Mode=TwoWay}" | |
ItemsSource="{Binding Patients}" | |
SelectedItem="{Binding SelectedPatient, Mode=TwoWay}" | |
SortingAlgorithm="{Binding SortingAlgorithm}" /> | |
<DatePicker Date="{Binding Appointment.AppointmentDate}" Format="dd/MM/yyyy" /> | |
<TimePicker Time="{Binding Appointment.AppointmentTime}" Format="HH:mm" /> | |
<material:MaterialEntry Text="{Binding Appointment.Subject}" Placeholder="Reason..." /> | |
</StackLayout> | |
</StackLayout> | |
</ContentPage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using DentalAssistantXF.Models; | |
using DentalAssistantXF.Services; | |
using DentalAssistantXF.Utils; | |
using Prism.Commands; | |
using Prism.Mvvm; | |
using Prism.Navigation; | |
using System; | |
using System.Collections.Generic; | |
using System.Collections.ObjectModel; | |
using System.Linq; | |
using Xamarin.Forms; | |
namespace DentalAssistantXF.ViewModels | |
{ | |
public class EditAppointmentPageViewModel : BindableBase, INavigatingAware | |
{ | |
private readonly IDatabaseService _databaseService; | |
private Appointment _appointment; | |
private Patient _selectedPatient; | |
private Patient _tempPatient; | |
private string _title; | |
private string _filterText; | |
public EditAppointmentPageViewModel(IDatabaseService databaseService) | |
{ | |
_databaseService = databaseService; | |
SaveAppointmentCommand = new DelegateCommand(SaveAppointment); | |
Patients = new ObservableCollection<Patient>(); | |
} | |
public Appointment Appointment | |
{ | |
get { return _appointment; } | |
set { SetProperty(ref _appointment, value); } | |
} | |
public Patient SelectedPatient | |
{ | |
get { return _selectedPatient; } | |
set { SetProperty(ref _selectedPatient, value); } | |
} | |
public string Title | |
{ | |
get { return _title; } | |
set { SetProperty(ref _title, value); } | |
} | |
public string FilterText | |
{ | |
get { return _filterText; } | |
set { SetProperty(ref _filterText, value); } | |
} | |
public Func<string, ICollection<string>, ICollection<string>> SortingAlgorithm { get; } = (text, values) => values | |
.Where(x => x.ToLower().StartsWith(text.ToLower())) | |
.OrderBy(x => x) | |
.ToList(); | |
public void OnNavigatingTo(NavigationParameters parameters) | |
{ | |
_tempPatient = null; | |
if (parameters != null) | |
{ | |
Appointment = (Appointment)parameters["Appointment"]; | |
Title = Appointment.Id < 1 ? "Add new appointment" : "Edit appointment"; | |
if (parameters["Patient"] != null) | |
{ | |
_tempPatient = (Patient)parameters["Patient"]; | |
} | |
GetPatientsAsync(); | |
} | |
} | |
public ObservableCollection<Patient> Patients { get; } | |
public DelegateCommand SaveAppointmentCommand { get; } | |
private async void GetPatientsAsync() | |
{ | |
var patients = await _databaseService.DentalAssistantDB.GetPatientsAsync(); | |
Patients.Clear(); | |
patients.ToList().ForEach(Patients.Add); | |
if (_tempPatient != null) | |
{ | |
SelectedPatient = Patients.Where(p => p.Id == _tempPatient.Id).FirstOrDefault(); | |
} | |
} | |
private async void SaveAppointment() | |
{ | |
if(SelectedPatient == null) | |
{ | |
HelperFunctions.ShowToastMessage(ToastMessageType.Error, "You have to select a patient first"); | |
return; | |
} | |
Appointment.PatientId = SelectedPatient.Id; | |
try | |
{ | |
if (await _databaseService.DentalAssistantDB.SaveAppointmentAsync(Appointment) > 0) | |
{ | |
HelperFunctions.ShowToastMessage(ToastMessageType.Success, "Appointment saved successfully"); | |
MessagingCenter.Send(this, Constants.OnAddOrEditAppointmentMsg); | |
MessagingCenter.Send(this, Constants.OnDashboardDataChangeMsg); | |
} | |
} | |
catch (Exception e) | |
{ | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment