簡體   English   中英

Xamarin表單/ XAML:未調用轉換器

[英]Xamarin Forms / XAML: Converter not called

有人知道為什么只調用第二個不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();
    }
}

感謝幫助。

根據Jason的提示,它現在正在工作! 我更改了xaml,以便ViewCell僅包含一個視圖。 在該視圖中,我添加了兩個具有binding屬性的相對布局。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM