Simple Proof of Concept (I would use a Converter for this, but am learning Markup Extensions)
This is based on the Evolve 2016 session https://evolve.xamarin.com/session/56e201d2bad314273ca4d813
I have a page bound to a simple model with a Label.
<Label
Text="{Binding Path=Amount1, StringFormat='{0:C}'}"
TextColor="{toolkit:FinancialColor PrettyMoney={Binding Amount1}}"></Label>
I need to send the Amount1
from the Model
to the IMarkupExtenion
FinancialColor
, but I get an error that PrettyMoney
has no property, bindable property or event.
Here's my MarkupExtension
public class FinancialColorExtension : IMarkupExtension
{
public decimal PrettyMoney { get; set; }
public object ProvideValue(IServiceProvider serviceProvider)
{
if (PrettyMoney == 0) return Color.Black;
if (PrettyMoney < 0) return Color.Red;
return Color.Green;
}
}