Declaring a converter in ContentView causes blank xamarin forms page

Viewed 745

Im going through the process of creating a test user control to be used on a page in a Xamarin Forms App. I want to pass in a theme as a string into the control from the test page and then convert that to a colour based on a few different factors such as user settings and application settings. However, as soon as I declare my converter in my ContentView, my page stops rendering and all I get is a blank page!

<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             x:Class="MyProject.UserControls.MyControl"
             xmlns:helpers="clr-namespace:MyProject.Converters"             >
    <ContentView.Resources>
        <helpers:StringToColourConverter x:Key="ColorConverter" />
    </ContentView.Resources>
    <ContentView.Content>
        <StackLayout x:Name="ControlRoot">
            <Label x:Name="PrimaryLabel" Text="{Binding PrimaryText}" />
            <Label x:Name="SecondaryLabel" Text="{Binding SecondaryText}" />
        </StackLayout>
    </ContentView.Content>
</ContentView>

If I comment out the following lines:

Then the page renders the primary and secondary labels as expected. But if its there (and not even used!) then the page is blank and I get no errors. I know the Converter is getting picked up OK as VS2017 auto-completes the namespace for me in the XML declaration and auto-completes the name StringToColourConverter if I type <helpers:, but the breakpoint in my converter is never hit so the code isn't even running.

Any ideas on what is failing here? Do I have to declare the coverter differently in a ContentView?

edit 1 For the converter, I've stripped it right back to make sure it isn't a code issue (I hope!):

public class StringToColourConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return Color.Red;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value.ToString();
        }
    }

Thanks

1 Answers
Related