0

Please help me to solve this problem

Error :XLS0415: The attachable property 'TrueObject' was not found in type 'BooleanToObjectConverter'. App1 RegstrationPage.xaml.

I try this Class property declaration in XAML but it do't work.. DependencyObject can not b inherit with class..

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

Here is BooleanToObjectConverte Class

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);
    }
}
Paul Kertscher
  • 9,416
  • 5
  • 32
  • 57
  • I used your code in your VS,i got the same result at the first time, but then i close this project in VS, then delete obj and Bin folder, and give administartor of this project, reopen the VS, build this project, this issue is disappear, it is so wired. – Leon Jan 31 '19 at 08:07
  • thank you.i try this and it works but when i stop debugging and write some other code ,these errors again appears and when i run again then it run successfully and no errors appear... – muhammad-zubair Jan 31 '19 at 08:25

1 Answers1

1

Don't make FalseObject and TrueObject static; they should be public instance properties.

Martin Robins
  • 6,033
  • 10
  • 58
  • 95