Binding with Converter using ConverterParameter Binding Not Working

JohnRennemeyer.6780JohnRennemeyer.6780 USMember
edited August 2015 in Xamarin.Forms

I'm trying to do the following:

Bind a Color property from based on the class property if the item is selected. If it is not selected, to color the Color gray. This is using a custom horizontal RepeaterView. The IsSelected property is a property on my object class which gets set to true in the repeaterview when the item has been clicked:

[ImplementPropertyChanged] //PropertyChanged.Fody implements events as needed for binding automatically public class Child : ISelectable { public bool IsSelected { get; set; } public Color IdentityColor { get; set; } }

BorderColor="{Binding IsSelected, Converter={StaticResource ChildSelectedColorConverter}}"

I've tried

BorderColor="{Binding IsSelected, Converter={StaticResource ChildSelectedColorConverter}, ConverterParameter={Binding IdentityColor}}"

and it did not work because from what I've read, you can't bind a property to the ConverterParameter because it is not a Dependency/Bindable Object.

I've also tried binding directly to the object, as follows and updating the converter to check the IsSelected and pass back the IdentityColor, but it doesn't updated the BorderColor when the IdentityColor has changed, I believe due to the fact that I'm binding against the whole object and it isn't being notified on the IsSelected being changed:

BorderColor="{Binding ., Converter={StaticResource ChildSelectedColorConverter}}"

Is it possible to make the {Binding .} propertychanged notify for the whole object when a child property has changed?

Since MultipleBindings aren't available in Xamarin.Forms yet, how can I get this to work as needed?

Thanks for your help,


Best Answer


  • stvansolanostvansolano UMInsider, University ✭✭✭
    edited August 2015

    Hey @Renzska objects passed as converter need to implement the IValueConverter interface to make it work. Haven't you implement it? Check this link example at the end of the page.

    Let me know

  • JohnRennemeyer.6780JohnRennemeyer.6780 USMember
    edited August 2015


    That did the trick. Needed to modify it for the specific type of CircleImage, but I got it.

    <Style x:Key="SelectedStyle" TargetType="controls:CircleImage"> <Style.Triggers> <DataTrigger TargetType="controls:CircleImage" Binding="{Binding IsSelected}" Value="True"> <Setter Property="BorderColor" Value="{Binding IdentityColor}" /> </DataTrigger> <DataTrigger TargetType="controls:CircleImage" Binding="{Binding IsSelected}" Value="False"> <Setter Property="BorderColor" Value="Gray" /> </DataTrigger> </Style.Triggers> </Style>

    and then:

    <controls:CircleImage Source="{Binding Photo}" BorderThickness="3" Aspect="AspectFill" WidthRequest="76" Style="{StaticResource SelectedStyle}"> </controls:CircleImage>

Sign In or Register to comment.