Martin Žid
Martin Žid

Reputation: 299

IValueConverter – Passing an object as ConverterParameter

In my Xamarin xaml file I have a ProgressBar, where I need to compute Progress (Value/Maximum). So I wrote my Convertor, but I am not able to pass the Maximum to the Convertor.

I tried to use ConverterParameter, but it does not support bindings...

<ProgressBar Progress="{Binding Progress.Value, 
    Converter={StaticResource Convertor}, ConverterParameter=??}" />

Am I doing something wrong or is there any workaround?

Upvotes: 1

Views: 2608

Answers (1)

Nick Peppers
Nick Peppers

Reputation: 3251

You could pass a reference directly into your converter if it's defined in xaml of whatever class/ViewModel that has all the values you need to calculate progress.

<ProgressBar x:Name="_progressBar" Progress="{Binding Progress.Value,
    Converter={StaticResource Convertor}, ConverterParameter={x:Reference _progressBar}}" />

or you could just pass in the value directly in xaml or as a static value defined in a static class from elsewhere in your app, which is of course if you know what the value will be ahead of time.

, ConverterParameter=1}" or
, ConverterParameter={x:Static local:DefaultValues.MaxValue}}"

However, it does sound like you could calculate Progress in your ViewModel on property changed before setting Progress.Value/Progress.MaxValue property, and then you wouldn't even need a converter.

Upvotes: 2

Related Questions