简体   繁体   中英

Xamarin Forms / XAML: Converter not called

Does anybody know why only the second isvisible converter gets called?
If I changed the sequence, then only the new second converter get called.
Converter1 is DiaryTypeNahrungsaufnahmeToBoolConverter and converter2 is 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>

The Converter code is:

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();
    }
}

Thanks for Help.

By the hint from Jason, it's working now! I changed the xaml, so that the ViewCell only consists one view. In that view I added my two relative layouts with the binding property.

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM