【发布时间】:2017-01-07 22:45:19
【问题描述】:
有人知道为什么只有第二个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();
}
}
感谢您的帮助。
【问题讨论】:
-
您的转换器的代码是什么?正如现在所说的那样,它太宽泛了,所以有太多可能的答案。请添加更多详细信息,否则将很难为您提供帮助。
-
@Demitrian 好的添加了转换器代码
-
您在哪里定义了
converter1和converter2?还是您只是使用这些名称来避免在代码中为您的问题输入转换器的名称? -
我认为问题在于您的 ViewCell 有两个孩子。一个 ViewCell 只有一个 View 属性,所以它只能有一个孩子。多个子项需要包含在一个布局中。
-
@Jason 是的,谢谢,就是这样!现在它正在工作! :)
标签: c# xaml xamarin xamarin.forms