MultiTrigger和Converter的困惑问题

时间:2019-06-10 19:26:17

标签: xamarin binding multitrigger

我有以下转换器:

公共类InverseBooleanConverter:IValueConverter     {         #region IValueConverter成员

Dir

并且我正试图像这样使用它,以基于代码隐藏属性“ CanShowResults”和页面上的活动指示器控制列表视图的IsVisible:

with open('april.txt', 'r') as inputfile:
    for line in inputfile:
        text = line[0]
        text = re.sub(r'-\n', '\n', text)\
        text = re.sub(r'https://proxygt-law.wrlc.org:443/login?qurl=', '', text)
    f.write(text + ;\n\)

。 。 。 。 。                              

在Convert方法中出现异常。我查看过文档,有人看到我在做什么错吗?

1 个答案:

答案 0 :(得分:0)

targetType用于指出将值转换为的类型。无需将其传递给IValueConverter类。它会根据要转换为的类型自动设置。

例如,如果您在标签文本上使用IValueConverter,则targetTypeSystem.String。您的targetType始终是System.Object,因为您是在BindingCondition上使用它的。

如果要手动指出类型,可以尝试ConverterParameter

<BindingCondition Binding="{Binding Source={x:Reference retrievingActivity}, Path=IsRunning, Converter={StaticResource boolInvert}, ConverterParameter={x:Type x:Boolean}}" Value="true" />

然后在IValueConverter类中检索它,例如:

try
{
    if ((Type)parameter != typeof(bool))
        throw new InvalidOperationException("The target must be a boolean");
}
catch (Exception ex)
{
    int x = 1;
}
return !(bool)value;

此外,我们像杰森所说的那样直接使用if (value is bool)

相关问题