Weitere ähnliche Inhalte
Ähnlich wie Xamarin Forms in Action (20)
Mehr von Constantine Mars (17)
Kürzlich hochgeladen (20)
Xamarin Forms in Action
- 3. Xamarin Forms. Init
Android project:
global::Xamarin.Forms.Forms.Init (this, bundle);
iOS project:
global::Xamarin.Forms.Forms.Init ();
- 5. 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>
- 6. 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>
- 9. Platform Specific. Common Interface
namespace MedChestAssistant
{
public interface INotificationHelper
{
void notify(String message);
}
}
- 10. 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 ()
{
}
}
}
- 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);
}