2

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;
    }
}
Ian Vink
  • 66,960
  • 104
  • 341
  • 555
  • 1
    You can only bind to `Bindable Properties` and only `BindableObjects` can have bindable properties. – Jesus Angulo Jul 19 '17 at 19:17
  • 1
    Also see failed attempt declaring BindableProperty: [IMarkupExtension with bindable property does not work](https://stackoverflow.com/q/42648334/199364) and a more ambitious approach to a somewhat different situation - *might* be relevant: [MarkupExtension for binding](https://stackoverflow.com/a/41997179/199364). – ToolmakerSteve Jul 15 '18 at 23:32

0 Answers0