Date post: | 17-Jan-2017 |
Category: |
Software |
Upload: | constantine-mars |
View: | 57 times |
Download: | 0 times |
Xamarin Forms in ActionMedchest Assistant
Project architecture. PCL
Xamarin Forms. Init
Android project:
global::Xamarin.Forms.Forms.Init (this, bundle);
iOS project:
global::Xamarin.Forms.Forms.Init ();
Xamarin Forms XAML
Xamarin Forms XAML
<ContentPage.Content>
<StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand">
<Label x:Name="label" Text="List of medicines” HorizontalOptions="Center" />
<StackLayout Orientation="Horizontal">
<Entry x:Name="nameEntry" HorizontalOptions="FillAndExpand" />
<DatePicker x:Name="datePicker" HorizontalOptions="End"/>
<Button x:Name="addButton" Text="Add" Clicked="add" HorizontalOptions="End" />
<Button x:Name="scanButton" Text="Scan" Clicked="scan" HorizontalOptions="End" />
</StackLayout>
<ListView x:Name="list" VerticalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding Name}" Detail="{Binding ExpireDate,
StringFormat='Expires: {0:MM-dd-yy}'}">
<TextCell.ContextActions>
<MenuItem Clicked="onDelete"
CommandParameter="{Binding .}" Text="Delete" IsDestructive="True" />
</TextCell.ContextActions>
</TextCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage.Content>
Xamarin Forms Bindings
<ListView x:Name="list" VerticalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding Name}" Detail="{Binding ExpireDate, StringFormat='Expires:
{0:MM-dd-yy}'}"> <TextCell.ContextActions>
<MenuItem Clicked="onDelete" CommandParameter="{Binding .}" Text="Delete"
IsDestructive="True" />
</TextCell.ContextActions>
</TextCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage.Content>
Platfrom specific designers
No XAML Designer
Platform Specific. Common Interface
namespace MedChestAssistant{
public interface INotificationHelper{
void notify(String message);}
}
Platform Specific. Interface Implementation
[assembly: Xamarin.Forms.Dependency (typeof (NotificationHelperImpl))]namespace MedChestAssistant.iOS{
public class NotificationHelperImpl: INotificationHelper{
#region INotificationHelper implementation
public void notify (string message){
var notification = new UILocalNotification();
// set notification params …
UIApplication.SharedApplication.ScheduleLocalNotification(notification);}#endregion
public NotificationHelperImpl (){}
}}
NuGet packages
Packages in project tree
Platform-specific initialisation
Android:
ZXing.Mobile.MobileBarcodeScanner.Initialize (Application);
iOS:
ZXing.Net.Mobile.Forms.iOS.Platform.Init();
iOS-specific notifications setup
if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) {var notificationSettings = UIUserNotificationSettings.GetSettingsForTypes (
UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, null
);
app.RegisterUserNotificationSettings (notificationSettings);}
Thank you. Questions?