I have a text binding in my XAML as follows:
Text="{Binding Converter={StaticResource ColumnToCaption}, ConverterParameter=-1}"
It simply takes the column number and looks up what the caption should be for that column based on data I have stored in a collection. That has been working fine but after one of the last set of upgrades to Visual Studio / Xamarin forms, the XAML intelisense started generating the error "Invalid Property Value". I didn't think much of it because the app seemed to work. Then some weird things started happing in my app and I noticed in my error list, I have a 43 "Invalid Property Value" errors listed (basically one for every place I use the ConverterParameter).
I double checked the MS documentation to ensure nothing changed (this link https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/data-binding/converters) and it still shows passing the value in as a number is OK. Here is the example from the MS documentation:
<Label Text="{Binding Red, Converter={StaticResource doubleToInt}, ConverterParameter=255,
StringFormat='Red = {0:X2}'}" />
I am simply trying to rule this out as the source of my problem but I cannot seem to find out how to get the error to go away. Any assistance would be appreciated.
OH here is the converter code just so you can see it:
public class ColumnToCaption : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string ls_ReturnValue = "";
try
{
if (System.Convert.ToInt32(parameter.ToString()) < 0)
{
if (App.gvm_AppSettings.AutoExpire)
{
ls_ReturnValue = AppResources.Time;
}
else
{
ls_ReturnValue = AppResources.CheckedIn;
}
}
else
{
ls_ReturnValue = App.gvm_AppSettings.FormFieldCaptionText(Int32.Parse(parameter.ToString()));
}
}
catch (Exception ex)
{
App.ProcessException(ex);
}
return ls_ReturnValue;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Could you not add a string resource?
...
<ContentPage.Resources>
<ResourceDictionary>
<converters:DoubleToInt x:Key="doubleToInt" />
<x:String x:Key="twoFiveFive">255</x:String>
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
...
<Label Text="{Binding Red, Converter={StaticResource doubleToInt}, ConverterParameter={StaticResource twoFiveFive}}" .../>
...
</ContentPage.Content>