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

Style on custom control property not supported ?

$
0
0

Hello,

i encounter troubles for styling my custom control.

I've created a customButton class which is inherited from Button. This class contains some bindable properties like this

public static readonly BindableProperty TextColorPressedProperty = BindableProperty.Create("TextColorPressed", typeof(Color?), typeof(CustomButton), null);
public Color? TextColorPressed
{
    set { SetValue(TextColorPressedProperty, value); }
    get { return (Color?)GetValue(TextColorPressedProperty); }
}

However, when i try to declare a custom style in my xaml...

<ContentPage.Resources>
<ResourceDictionary>

    <Style x:Key="CustomButtonBaseStyle" TargetType="cc:CustomButton">
        <Setter Property="BackgroundColor" Value="Red"/>
        <Setter Property="TextColor" Value="Blue"/>
        <Setter Property="TextColorPressed" Value="Blue"/>
    </Style>

</ResourceDictionary>
</ContentPage.Resources>

I just get a crash

[ERROR] FATAL UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidProgramException: Invalid IL code in XPlatformApp.Views.ButtonsPage:InitializeComponent (): IL_0234: newobj    0x0a000083

If i comment "TextColorPressed" property in my custom style, everything is ok.

Any idea about the right way to integrate custom bindable property into a style template ?


Viewing all articles
Browse latest Browse all 77050

Trending Articles