Most of iPhone and iPad users can easily recognize icon badges - the pattern for application notifications typically presented in app icon or navigation bar. People that got used to this pattern might want to have the same user experience in their Xamarin Forms application. This post describes how to customize the navigation toolbar in iOS to dynamically display such elements.
Tappable label in Xamarin.Forms
Adding tap/click handling to Xamarin.Forms Label is fairly easy. You can do it both in XAML or code behind using GesureRecognizers
collection like it is described in this recipe. Unfortunately if you plan to use this solution intensively in your app it will add quite a lot of repeatable code for setting up those handlers (especially in XAML)
In this short recipe I will show how to implement a custom control that is easy to use and potentially to extend if needed.
Cleaning ADAL token cache on Android and iOS
Microsoft Azure Active Directory Authentication Libraries (ADAL) is a popular set wrapper around Azure Active Directory API distributed in the form of platform and language specific components. It’s especially useful in multi-platform applications that integrate with various AD APIs such as Outlook or Graph API. It not only wraps the oAuth endpoints but automates the entire application flow for retrieving, refreshing and persisting tokens.
Unfortunately, among many features, ADAL does not provide the logout functionality out of the box. Let’s see how to implement this in few simple steps.
Disabled button style on iOS in Xamarin.Forms
All the credits for solution described in this post goes my friend qbus. He saved few hours of my life and my sanity ;-)
In Xamarin.Forms application I have a button with non-default styling (defined in XAML). Target platforms are iOS and Android. Enabled and disabled states should obviously be distinguished with colors.
The most straightforward solution that makes use of Data Triggers works well for Android. For some reason it doesn’t want to work properly on iOS. If the button is initially disabled it displays correctly in this state but after changing IsEnabled
to true
and then back to false
it does not anymore. Interestingly the background taken from style setter is good, but not the text color property.
ModernHttpClient and 'Type HttpClientHandler defined in unreferenced assembly' error
ModernHttpClient is a great wrapper around native HTTP clients offered by Xamarin. It wraps NSURLSession
on iOS and OkHttp
on Android. As it deals pretty well with SSL/TLS stack (especially in uncommon scenarios) it’s often used instead of built-in types. I switched to ModernHttpClient
because of weird errors on connections to the preproduction environment in Android.