A new feature was merged into the Xamarin.Forms repository. This time: TextColor for the TableSection control. With this new feature, you can specify the color of the text that is used in a table section. A small feature, but each is one, right? 😉 In this post, we will look at how the implementation is done and how to use it.
A user of Xamarin.Forms on GitHub opened an issue which pretty much states: I want to be able to set the text color color within a table section. For you who don’t know what a table section is, you can see it in the image underneath.
In practice, it’s a variant of the ListView control with some distinct features on how it looks. If we go back to the description of the issue, the wish of that user was to be have an out-of-the-box way to set the text color of the text that says: Section 1 and Section 2.
Implementing this feature was actually pretty straight-forward. The TableSection is really just a TextCell under the hood. And the TextCell already supports the TextColor. Hooray!
That means it was just a matter of feeding the color value through to where the table section was composed and it worked! I could walk you through all the details, but actually, it would be pretty boring. The hard thing to do was to locate where the TableSections were created and hook into that to set the actual color. Depending on each platform this was pretty easy or just a breeze.
If you want to see all the nitty-gritty details, check out the PR and the commits behind it. The actual cool thing is that I got it to work on all supported platforms. That means: iOS, Android, UWP, Mac OS, Tizen, WPF and GTK.
For this implementation, I thought it would be a nice challenge to get a 100% platform coverage. This is actually quite hard to achieve. Across the different platforms, not all features are supported. In the ideal situation, you would just map an abstract Xamarin
For Tizen, the implementation was actually quite easy, just like the rest. It was verifying that it worked which was quite hard. This is actually why I wrote a small blog on how I did it. You can read it here.
Usage is pretty easy. First, let’s have a look at the XAML that is used for the image above.
With the version of Xamarin.Forms installed that incorporates this new feature (not known at the time of writing) you can now simply apply a TextColor to the TableSection like this:
The result (which, convienently, doesn’t match this code), will then look something like in the image below.
I hope you enjoyed reading this post on how a feature of Xamarin.Forms came together. I really enjoy helping out the Forms team lately and it helps creating some nice blog posts 😉