Mastering Xamarin UI Development
Build robust and a maintainable cross-platform mobile UI with Xamarin and C# 7, 2nd Edition
Steven F. Daniel
- 584 páginas
- English
- ePUB (apto para móviles)
- Disponible en iOS y Android
Mastering Xamarin UI Development
Build robust and a maintainable cross-platform mobile UI with Xamarin and C# 7, 2nd Edition
Steven F. Daniel
Información del libro
Learn how to build stunning, maintainable, cross-platform mobile application user interfaces using C# 7 with the power of both the Xamarin and Xamarin.Forms frameworks.
Key Features
- Build effective native and cross-platform user interfaces using the Xamarin frameworks for iOS and Android, as well as Xamarin.Forms
- Maximize the testability, flexibility, and overall quality of your Xamarin mobile apps
- Step-by-Steps guide that is packed with real-world scenarios and solutions, to build professional grade mobile apps and games for the iOS and Android platforms, using C# 7
Book Description
This book will provide you with the knowledge and practical skills that are required to develop real-world Xamarin and Xamarin.Forms applications. You'll learn how to create native Android app that will interact with the device camera and photo gallery, and then create a native iOS sliding tiles game. You will learn how to implement complex UI layouts and create customizable control elements based on the platform, using XAML and C# 7 code to interact with control elements within your XAML ContentPages.
You'll learn how to add location-based features by to your apps by creating a LocationService class and using the Xam.Plugin.Geolocator cross-platform library, that will be used to obtain the current device location. Next, you'll learn how to work with and implement animations and visual effects within your UI using the PlatformEffects API, using C# code.
At the end of this book, you'll learn how to integrate Microsoft Azure App Services and use the Twitter APIs within your app. You will work with the Razor Templating Engine to build a book library HTML5 solution that will use a SQLite.net library to store, update, retrieve, and delete information within a local SQLite database. Finally, you will learn how to write unit tests using the NUnit and UITest frameworks.
What you will learn
- Downloading and Installing the Visual Studio for Mac IDE
- Overview and Understanding of the Xamarin Mobile Platform
- Understand the MVVM architectural pattern and how to implement this with your apps
- Build a NavigationService class to enable navigation between your ViewModels
- Implement Data-Binding to control elements within your XAML pages and ViewModels
- Create and Implement Xamarin.Forms Animations within your applications
- Work with the Microsoft Azure App Services Platform and the Facebook SDK
Who this book is for
This book is intended for readers who have experience using at least the C# 6.0 programming language and interested in learning how to create stunning native, and cross-platform user interfaces for the iOS and Android platforms using the Xamarin and Xamarin.Forms frameworks using C# 7.
Preguntas frecuentes
Información
Customizing the User Interface
- Customizing the DataTemplate in the WalksMainPage to lay out content neatly
- Customizing Padding and Margins in your XAML pages
- Creating and implementing various Xamarin.Forms Styles in your XAML Pages
- Implementing RoutingEffects to access platform-specific PlatformEffects using C#
- Implementing PlatformEffects to customize the appearance of control elements using C#
- Implementing ValueConverters and ImageConverters in your app using C#
- Updating the BaseViewModel class to include additional properties using C#
Customizing the DataTemplate in the WalksMainPage
- Locate and open the WalksMainPage.xaml file, which is located in the Views folder, ensure that it is displayed in the code editor, and enter the following highlighted code sections:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TrackMyWalks.Views.WalksMainPage">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Add" Clicked="AddWalk_Clicked" />
</ContentPage.ToolbarItems>
<StackLayout>
<ListView x:Name="WalkEntriesListView" HasUnevenRows="true"
SeparatorColor="#ddd" ItemTapped="myWalkEntries_ItemTapped">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.ContextActions>
<MenuItem Clicked="OnEditItem"
CommandParameter="{Binding .}" Text="Edit"
IsDestructive="False" />
<MenuItem Clicked="OnDeleteItem"
CommandParameter="{Binding .}" Text="Delete"
IsDestructive="True" />
</ViewCell.ContextActions>
<StackLayout x:Name="cellLayout" Padding="2,2"
Orientation="Horizontal" HorizontalOptions="FillAndExpand">
<Image Aspect="AspectFill" Source="{Binding ImageUrl}"
WidthRequest="140" HeightRequest="140"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand" />
<StackLayout x:Name="DetailsLayout" Padding="5,0"
HorizontalOptions="FillAndExpand">
<Label Text="{Binding Title}"
FontAttributes="Bold"
TextColor="Black">
<Label.FontSize>
<OnPlatform x:TypeArguments="x:Double">
<On Platform="Android, WinPhone" Value="14" />
<On Platform="iOS" Value="16" />
</OnPlatform>
</Label.FontSize>
</Label>
<Label Text="{Binding Distance,
StringFormat='Kilometers: {0} km'}"
FontAttributes="Bold" FontSize="12"
TextColor="#666" />
<Label Text="{Binding Difficulty,
StringFormat='Difficulty: {0}'}"
FontAttributes="Bold" FontSize="12"
TextColor="Black" />
<StackLayout Spacing="3" Orientation="Vertical">
<Label Text="{Binding Description}"
FontAttributes="None" FontSize="12"
TextColor="Blue"
VerticalOptions="FillAndExpand" />
</StackLayout>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
- We started by making some minor changes to our DataTemplate by defining a Label.FontSize attribute, which will set the FontSize based on the platform that our app is running on using the OnPlatform and specifying the x:TypeArguments of Double
- We used the On Platform attribute, passed in each platform that we want to check for, and assigned the font size value for each platform prior to defining the Spacing and Orientation values for our StackLayout to display the Description that is associated with each trail
Applying padding and margins to XAML layouts
Updating the WalksMainPage user interface using XAML
- Locate and open the WalksMainPage.xaml file, which is located in the Views folder, ensure that it is displayed in the code editor, and enter the following highlighted code sections:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TrackMyWalks.Views.WalksMainPage">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Add" Clicked="AddWalk_Clicked" />
</ContentPage.ToolbarItems>
<StackLay...