Xamarin Forms in Action
Medchest 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>
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?
constantine.mars@gmail.com

Xamarin Forms in Action

  • 1.
    Xamarin Forms inAction Medchest Assistant
  • 2.
  • 3.
    Xamarin Forms. Init Androidproject: global::Xamarin.Forms.Forms.Init (this, bundle); iOS project: global::Xamarin.Forms.Forms.Init ();
  • 4.
  • 5.
    Xamarin Forms XAML <ContentPage.Content> <StackLayoutOrientation="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>
  • 6.
    Xamarin Forms Bindings <ListViewx: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>
  • 7.
  • 8.
  • 9.
    Platform Specific. CommonInterface namespace MedChestAssistant { public interface INotificationHelper { void notify(String message); } }
  • 10.
    Platform Specific. InterfaceImplementation [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 () { } } }
  • 11.
  • 12.
  • 13.
  • 14.
    iOS-specific notifications setup if(UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) { var notificationSettings = UIUserNotificationSettings.GetSettingsForTypes ( UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, null ); app.RegisterUserNotificationSettings (notificationSettings); }
  • 15.