Xamarin.forms: [Enhancement] Switch Text Property

Created on 3 Jul 2019  Â·  5Comments  Â·  Source: xamarin/Xamarin.Forms

Summary

The switch control should have a Text property alongside all possible customizations of a Label control

API Changes

Currently this is how I implement my switch with information.
<StackLayout Orientation="Horizontal">
<Switch x:Name="SendConfirmationEmailCheck" />
<Label Text="Send me a confirmation email" Style="{DynamicResource EntryLabelStyle}" />
</StackLayout>

It would be nice to have something like
<Switch x:Name="SendConfirmationEmailCheck" Text="Send me a confirmation email" TextStyle="{DynamicResource EntryLabelStyle}"/>

In C#, the declaration would be something like
var SendConfirmationEmailCheck=new Switch(){Text="Send me a confirmation email"};

Intended Use Case

  • Setting text properties to switch at declaration without having to use more controls
  • Setting style to the text property either from XAML or C#
proposal-open enhancement âž•

All 5 comments

eg UWP has two properties for the switch text, with On and Off values. Might as well use a similar pattern here.

I agree. There needs to be an On and Off text property.

Plus one for this also should be easier to changed the color and height and width of the switch.

I understand the need here, but here's what bothers me:

  • support in platforms for this control is not uniform
  • the layout preferences (where to put the label and the switch relatively to each other) aren't set, and will depend from user to user.

So I don't see us providing a control, backed with platform renderers for this. Instead, I think this should be implemented using TemplatedView, aggregating a Label and a switch. This way, the layout will be modifiable by switching the ControlTemplate.

If someone wants to give it a try, that would be the first templated control we might end up merging...

Any progress?

Was this page helpful?
0 / 5 - 0 ratings