Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin.forms Xamarin Forms ConverterParameter XAML错误无效的属性路径语法_Xamarin.forms_Data Binding_Ivalueconverter - Fatal编程技术网

Xamarin.forms Xamarin Forms ConverterParameter XAML错误无效的属性路径语法

Xamarin.forms Xamarin Forms ConverterParameter XAML错误无效的属性路径语法,xamarin.forms,data-binding,ivalueconverter,Xamarin.forms,Data Binding,Ivalueconverter,我的XAML中有一个文本绑定,如下所示: Text="{Binding Converter={StaticResource ColumnToCaption}, ConverterParameter=-1}" 它只需要获取列号,并根据我存储在集合中的数据查找该列的标题。这一直运行良好,但在对VisualStudio/Xamarin表单进行最后一次升级后,XAML IntelliSense开始生成错误“Invalid Property Value”。我没怎么想,因为这个应用程序

我的XAML中有一个文本绑定,如下所示:

Text="{Binding Converter={StaticResource ColumnToCaption}, ConverterParameter=-1}"
它只需要获取列号,并根据我存储在集合中的数据查找该列的标题。这一直运行良好,但在对VisualStudio/Xamarin表单进行最后一次升级后,XAML IntelliSense开始生成错误“Invalid Property Value”。我没怎么想,因为这个应用程序似乎很有效。然后一些奇怪的事情开始在我的应用程序中发生,我注意到在我的错误列表中,我列出了43个“无效属性值”错误(基本上我使用ConverterParameter的每个地方都有一个)

我仔细检查了MS文档以确保没有任何更改(此链接),它仍然显示以数字形式传递值是可以的。以下是MS文档中的示例:

 <Label Text="{Binding Red, Converter={StaticResource doubleToInt}, ConverterParameter=255,
     StringFormat='Red = {0:X2}'}" />

我只是试图排除这个问题的根源,但我似乎无法找出如何消除错误。任何协助都将不胜感激

哦,这是转换器代码,您可以看到:

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();
    }
}
公共类ColumnToCaption:IValueConverter
{
公共对象转换(对象值、类型targetType、对象参数、CultureInfo区域性)
{
字符串ls_ReturnValue=“”;
尝试
{
if(System.Convert.ToInt32(parameter.ToString())<0)
{
如果(App.gvm\u AppSettings.AutoExpire)
{
ls_ReturnValue=通知来源时间;
}
其他的
{
ls_ReturnValue=AppResources.CheckedIn;
}
}
其他的
{
ls_ReturnValue=App.gvm_AppSettings.FormFieldCaptionText(Int32.Parse(parameter.ToString());
}
}
捕获(例外情况除外)
{
App.ProcessException(ex);
}
返回ls_ReturnValue;
}
公共对象转换回(对象值、类型targetType、对象参数、CultureInfo区域性)
{
抛出新的NotImplementedException();
}
}

您不能添加字符串资源吗

...
<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>
。。。
255
...
...

您仍然可以运行该应用程序吗?当您使用相同的xaml创建新应用程序时,是否会出现相同的错误?是的,应用程序仍在运行,但奇怪的事情正在发生,我正在尝试解决这些错误,以确保它们不是问题的根源。我还没有尝试过一个新的项目,因为我正在尝试将这个项目推出。如果应用程序仍然运行,意味着代码是正确的,我不确定是什么原因导致这些错误。通常的方法是删除bin和obj以进行清理和重建。好的,我会试试。ThanksI删除了bin和obj文件,没有任何区别。