Just a few weeks ago we shipped Xamarin.Forms 4.0, which introduced the new Shell navigation for quickly bootstrapping your applications. As well as image source unification to make it convenient to use the same images everywhere, like the new FontImageSource. Several months ago our very own James Montemagno submitted a pull request introducing a CheckBox control. In recent days we also shipped a service release to quickly respond to the feedback you sent us. You’re not slowing down, and neither are we!
Today we are shipping a pre-release of our next version, Xamarin.Forms 4.1. Here’s is what is in store for you.
CheckBox has Arrived
Our team worked with James to get CheckBox across the line, and we’re excited to now share it with you. We have also provided Material versions of CheckBox
when you use Visual.
<CheckBox IsChecked="True" Color="Blue" />
Android
iOS
UWP
CheckBox is implemented for many platforms:
- iOS
- Android
- UWP
- MacOS
- WPF
This control marks another significant step in the transition of Xamarin.Forms from being platform focused, to being customer focused. Previously, if a control did not exist on all of the primary Xamarin.Forms platforms of Android, iOS, and UWP then it was considered platform specific and would not be implemented. Today, however, when we hear that you need a cross-platform control that isn’t present on 1 of the 3 platforms, we will consider how we can meet that need for you.
Improved Text Scaling for iOS Accessibility
We now use the iOS preferred font scaling features, so your fonts will magically size in response to the user’s accessibility preferences when you used named font sizes. And there are more sizes to now choose from:
- Large = 4,
- Body = 5,
- Header = 6,
- Title = 7,
- Subtitle = 8,
- Caption = 9
Developers Love Maps
One of the great benefits of writing native cross-platform apps is having the native maps at your fingertips. Frequent contributor, Andrei Nitescu, has once again sent a flurry of very useful enhancements, this time for maps.
ItemTemplateSelector
In version 3.6, Andrei added ItemsSource
to Maps so you could generate pins on your map based on bindings. Now, in version 4.1, you can also use a template selector to display different templates according to your need.
<ContentPage.Resources> <ResourceDictionary> <local:MapItemTemplateSelector x:Key="MapItemTemplateSelector"> <local:MapItemTemplateSelector.DataTemplate> <DataTemplate> <map:Pin Position="{Binding Position}" Address="{Binding Address}" Label="{Binding Description}" /> </DataTemplate> </local:MapItemTemplateSelector.DataTemplate> </local:MapItemTemplateSelector> </ResourceDictionary> </ContentPage.Resources> <map:Map ItemsSource="{Binding Places}" ItemTemplateSelector="{StaticResource MapItemTemplateSelector}" />
class MapItemTemplateSelector : DataTemplateSelector { public DataTemplate DataTemplate { get; set; } protected override DataTemplate OnSelectTemplate(object item, BindableObject container) { return DataTemplate; } }
Where Did You Click?
This seems like a fundamental thing you might want to know, and it looks like Joe Manke thought so too. With Joe’s contribution, you can get that information by subscribing to the MapClicked
event on your map. You will then get back coordinates indicating where the user touched down.
<map:Map MapClicked="Handle_MapClicked" />
void Handle_MapClicked(object sender, MapClickedEventArgs e) { Debug.WriteLine($"Last MapClick: {e.Position.Latitude}, {e.Position.Longitude}"); }
Locating Children in Control Templates
Sometimes it’s really helpful to get a reference to a control within a control template. Once again, it’s Andrei Nitescu to the rescue! His contribution allow you to do just that with a new method:GetTemplateChild
and a convenient new lifecycle method:Â OnApplyTemplate
.
<controls:MyCustomControl... > <controls:MyCustomControl.ControlTemplate> <ControlTemplate> <Label x:Name="myLabel"/> </ControlTemplate> <controls:MyCustomControl.ControlTemplate> </controls:MyCustomControl>
class MyCustomControl : TemplatedView { Label _myLabel; protected override OnApplyTemplate() { _myLabel = GetTemplateChild("myLabel"); } }
All the Platforms Get Love
While our core efforts continue to show up first and foremost on Android and iOS, there is no lack of activity among the other platforms, starting with Tizen. Samsung has been busy keeping up with us by adding support for Shell, Visual, Material renderers, named font sizes, and CollectionView among other things.
UWP, macOS, WPF, and GTK all made forward progress in this release. Thank you to all the amazing contributors.
Update Today
Xamarin.Forms 4.1-pre1 is ready for you to go hands-on. So open up your favorite NuGet manager and update a project with CheckBox today. If you discover something wrong, please let us know immediately by filing a helpful report on GitHub.
For a detailed look at everything included, check out the release notes. And a special thank you to all who contributed to this release. Your contributions are now immortalized in the release notes.
Not ready to take the leap yourself? Head over to my Twitch channel to watch how I upgrade the Xappy project and work on implementing these new updates to give you an idea how it all works and why you should be excited about the latest release.
Any idea how to work a checkbox within a collectionview.
I need to select the check and get the selected item, the checkbox is inside my collectionview
Will there be CarouselView enhancements/fixes in 4.1? I’m currently stuck on 3.4 since the stripped down CarouselView that’s now within the Xamarin.Forms component breaks a lot of my code. Another dev commented in a forum post and said it would be addressed in 4.1.