Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

"Binding: 'CornerRadius' can not be converted to type 'Single'." warning in custom control

$
0
0

I've enhanced a sample custom ImageButton control to support several additional bound properties. The problem arises with the CornerRadius property; all of the other additional bound properties behave as expected. Here's the XAML for the control:

<?xml version="1.0" encoding="UTF-8" ?>
<ContentView x:Class="GLLControlsLib.ImageButton"
             xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             HeightRequest="60"
             WidthRequest="120">
    <Frame x:Name="OuterFrame">
        <StackLayout Orientation="Horizontal">
            <Image x:Name="InnerImage"
                   HorizontalOptions="EndAndExpand"
                   VerticalOptions="CenterAndExpand" />
            <Label x:Name="InnerLabel"
                   HorizontalOptions="StartAndExpand"
                   VerticalOptions="CenterAndExpand" />
        </StackLayout>
    </Frame>
</ContentView>

Here is the bound property that allows the user to supply the Frame control with a CornerRadius. The Xamarin CornerRadius is a struct wrapping several doubles used to contain the corners of the control:

```
#region CornerRadius (Bindable CornerRadius) - applies to OuterFrame

    public static readonly BindableProperty CornerRadiusProperty =
        BindableProperty.Create( propertyName:  nameof(CornerRadius),
                                                 returnType:        typeof(CornerRadius),
                                                 declaringType:   typeof(ImageButton),
                                                 defaultValue:      default(CornerRadius) );
    public CornerRadius CornerRadius
    {
        get => (CornerRadius)GetValue( CornerRadiusProperty );
        set => SetValue( CornerRadiusProperty, value );
    }
    #endregion CornerRadius (Bindable CornerRadius)

        OuterFrame.SetBinding( Frame.CornerRadiusProperty, new Binding( "CornerRadius", source: this ) );

```

The problem is that I receive this warning message at runtime when an instance of the control is created:

    **[0:] Binding: 'Xamarin.Forms.CornerRadius' can not be converted to type 'System.Single'.**

...and I have no idea why the message is being issued. I do not use "System.Single" anywhere in my code; nowhere is a CornerRadius being converted to a Single in my code.

Can anyone offer a clue?


Viewing all articles
Browse latest Browse all 77050

Trending Articles