Reputation: 32758
I am using a template like this:
<template:ButtonTemplate ButtonType="2" Grid.Column="0" Text="{Binding FBtnText}"
LabelTextColor="{Binding FBtnLabelTextColor, Converter={StaticResource StringToColorConverter}"
TapCommand="{Binding FBtnCmd }" />
So the value of the color is entered as "#FF0000" and the converter then converts this into a color.
Is there a way that I could do this conversion in the binding itself so that I would not need to use the StringToColor converter?
Here's my binding that I am using right now:
public static readonly BindableProperty LabelTextColorProperty =
BindableProperty.Create(
nameof(LabelTextColor),
typeof(Color),
typeof(ButtonTemplate),
Color.FromHex("C9C9C9"));
public Color LabelTextColor
{
get { return (Color)GetValue(LabelTextColorProperty); }
set { SetValue(LabelTextColorProperty, value); }
}
Upvotes: 0
Views: 73
Reputation: 676
You don't need to use a Converter, Xamarin Forms accepts by default a string as a Color, you just have to use like this: "#XXXXXX". You could just pass "#FF0000" and it would be accepted.
Upvotes: 2