Home > Enterprise >  How to add binding property to Label with converter BoolToObjectConverter
How to add binding property to Label with converter BoolToObjectConverter

Time:09-06

I've the next converter code like the example in this post BoolToObjectConverter class

CodePudding user response:

This is not something that you should be using a converter for tbh, what you should be doing instead is assigning your ImageSource through a boolean or keeping the condition for this in your VM where this is directly handled. Converters are usually used in scenarios where you have value conversions.

But if you still insist on using this approach then there are some basic changes that you will need to do first of all you are misunderstanding what Source means here,

<Binding Source="{Binding DeviceHasScanner}">

Source in the above code does not mean the property which you need to provide but the context in which you wanna perform the lookup, that is the reason when you see the object it just copy-pastes the name you have as binding here, Now Source is only required if your Converter should be looking up in a particular context. I am pretty sure this is not the case here so all you need to do is give the Path property the value of your Binding.

So this <Binding Source="{Binding DeviceHasScanner}"> would become something like

<Binding Path="DeviceHasScanner"/>

Now here if your Source is in the same Binding Context you won't need to do anything but if it's not then you need to provide the reference of your BindingContext as shown in the example you can find https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/data-binding/converters#binding-converter-properties

Good luck!!

  • Related