首页 文章

Xamarin Forms / XAML:未调用转换器

提问于
浏览
0

有人知道为什么只有第二个 isvisible 转换器被调用吗?
如果我更改了序列,则只调用新的第二个转换器 .
Converter1是 DiaryTypeNahrungsaufnahmeToBoolConverter ,converter2是 DiaryTypeAuswirkungToBoolConverter .

<ListView>
  <ListView.ItemTemplate>
    <DataTemplate>      
        <ViewCell>
            <RelativeLayout IsVisible="{Binding Type, Converter={StaticResource converter1}}"></RelativeLayout>
            <RelativeLayout IsVisible="{Binding Type, Converter={StaticResource converter2}}"></RelativeLayout>
        </ViewCell>
    </DataTemplate>
  </ListView.ItemTemplate>
</ListView>

转换器代码是:

public class DiaryTypeNahrungsaufnahmeToBoolConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        try
        {
            if (value is LibChemotherapie.DiaryType)
            {
                return ((LibChemotherapie.DiaryType)value) == LibChemotherapie.DiaryType.Food;
            }
            return false;
        }
        catch (Exception)
        {
            return false;
        }

    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

public class DiaryTypeAuswirkungToBoolConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        try
        {
            if (value is LibChemotherapie.DiaryType)
            {
                return ((LibChemotherapie.DiaryType)value) == LibChemotherapie.DiaryType.Effect;
            }
            return false;
        }
        catch (Exception)
        {
            return false;
        }
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

感谢帮助 .

1 回答

  • 0

    根据杰森的暗示,它现在正在运作!我更改了xaml,因此ViewCell只包含一个视图 . 在该视图中,我添加了两个相对布局和绑定属性 .

    <ListView>
      <ListView.ItemTemplate>
        <DataTemplate>      
            <ViewCell>
                <RelativeLayout>
                    <RelativeLayout IsVisible="{Binding Type, Converter={StaticResource converter1}}"></RelativeLayout>
                    <RelativeLayout IsVisible="{Binding Type, Converter={StaticResource converter2}}"></RelativeLayout>
                </RelativeLayout>
            </ViewCell>
        </DataTemplate>
      </ListView.ItemTemplate>
    </ListView>
    

相关问题