We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Can't compile Style if I define TargetType as {x:Type buttons:SfButton} instead of buttons:SfButton when VisualStateManager.VisualStateGroups defined

I can't compile and Visual Studio tell me this:

Cannot convert value"BackgroundColor" to "Xamarin.Forms.BindableProperty".(XFC0040)

My code is the next:

<Style x:Key="BaseButton" TargetType="{x:Type buttons:SfButton}">
    <Setter Property="TextColor" Value=#F1F1F1" />
    <Setter Property="BackgroundColor" Value="#F5AF27" />
    <Setter Property="VisualStateManager.VisualStateGroups">
            <VisualStateGroup x:Name="CommonStates">
                <VisualState x:Name="Normal">
                        <Setter Property="BackgroundColor" Value="#F5AF27" />
                <VisualState x:Name="Disabled">
                        <Setter Property="BackgroundColor" Value="#33F5AF27" />

I'm doing something wrong or may be is a bug?

5 Replies

SR Shivani Ramakrishnan Syncfusion Team February 27, 2023 12:42 PM UTC

Hi Asier,


Query: Cannot compile Style when TargetType is defined as {x:Type buttons:SfButton} instead of buttons:SfButton


Thank you for contacting Syncfusion Support.


Style cannot be compiled in  {x:Type buttons:SfButton} because x:Type is used to set attribute System.Type object. And also similar error issue occured in Button control. So kindly use the control explicitly like buttons: SfButton to apply style.


We have attached a sample for your reference. Kindly refer to the sample and please let us know if you need any other details.



Attachment: SfButtonStyles_2d538ba5.zip

AS Asier February 28, 2023 01:05 PM UTC

Thank you for your response. I wanted to use {x:Type xxx} because I thought that it was the better way to do it because I believed that it was more detailed for the compiler.

If it's not too much to ask, could you pass me any page where explain diferences between use a Type or directly the control for the Style?

Thanks a lot.

VV Vijayakumar Viswanathan Syncfusion Team March 1, 2023 05:07 PM UTC

AS Asier March 2, 2023 10:37 PM UTC

Thanks a lot for your clarify response.

VV Vijayakumar Viswanathan Syncfusion Team March 3, 2023 02:22 AM UTC

Hi Asier,

We are glad that the workaround we offered was successful for you. We will be closing this forum thread, if you require any further information, please open a new one.


Vijayakumar V

Live Chat Icon For mobile
Up arrow icon