请帮助我解决此问题
错误:XLS0415:在以下位置找不到可附加属性“ TrueObject” 类型“ BooleanToObjectConverter”。 App1 RegstrationPage.xaml。
我尝试了这个Class property declaration in XAML,但是它不起作用。.DependencyObject无法b继承类。
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:App1"
xmlns:local1="clr-namespace:App1.Behavior"
x:Class="App1.RegstrationPage" Padding="50,20">
<ContentPage.Resources>
<ResourceDictionary>
<local:BooleanToObjectConverter x:Key="boolToStyleImage" x:TypeArguments="Style">
<local:BooleanToObjectConverter.FalseObject>
<Style TargetType="Image">
<Setter Property="HeightRequest" Value="20" />
<Setter Property="Source" Value="{local1:ImageResource App1.Images.error.png}" />
</Style>
</local:BooleanToObjectConverter.FalseObject>
<local:BooleanToObjectConverter.TrueObject>
<Style TargetType="Image">
<Setter Property="HeightRequest" Value="20" />
<Setter Property="Source" Value="{local1:ImageResource App1.Images.success.png}" />
</Style>
</local:BooleanToObjectConverter.TrueObject>
</local:BooleanToObjectConverter>
<local:BooleanToObjectConverter x:Key="boolToStyleEmail"
x:TypeArguments="Style">
<local:BooleanToObjectConverter.FalseObject>
<Style TargetType="Label" BasedOn="{StaticResource baseStyle}">
<Setter Property="TextColor" Value="#F44336" />
<Setter Property="Text" Value="Enter a valid email" />
</Style>
</local:BooleanToObjectConverter.FalseObject>
<local:BooleanToObjectConverter.TrueObject>
<Style TargetType="Label" BasedOn="{StaticResource baseStyle}">
<Setter Property="TextColor" Value="#4CAF50" />
<Setter Property="Text" Value="Your email looks good" />
</Style>
</local:BooleanToObjectConverter.TrueObject>
</local:BooleanToObjectConverter>
这是BooleanToObjectConverte类
public class BooleanToObjectConverter<T> :IValueConverter
{
public static T FalseObject { get; set; }
public static T TrueObject { get; set; }
public object Convert(object value, Type targettype,
object parameter, CultureInfo culture)
{
return (bool)value ? TrueObject : FalseObject;
}
public object ConvertBack(object value, Type targettype,
object parameter, CultureInfo culture)
{
return ((T)value).Equals(TrueObject);
}
}
答案 0 :(得分:1)
不要将FalseObject和TrueObject设为静态;它们应该是公共实例属性。