Forum Xamarin.Forms


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

How is it suggested to inherit from an implicit style?

TaylorBuchananTaylorBuchanan USMember ✭✭
edited August 2016 in Xamarin.Forms

I am having some issues inheriting from an implicit style defined in an Application ResourceDictionary. I have tried a couple of different approaches, but each has been unsuccessful in one form or another.

Attempt 1: Inherit from implicit style

Application ResourceDictionary:

<Style TargetType="Button">
    <Setter Property="BackgroundColor" Value="#1386F1" />
    <Setter Property="TextColor" Value="White" />
    <Setter Property="FontAttributes" Value="Bold" />
    <Setter Property="HeightRequest">
      <OnPlatform x:TypeArguments="x:Double" iOS="30" Android="50" />
      <Trigger TargetType="Button" Property="IsEnabled" Value="False">
        <Setter Property="BackgroundColor">
          <OnPlatform x:TypeArguments="Color" iOS="#E8E8E8" />

Page ResourceDictionary

<Style x:Key="LoginButtonStyle" TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
    <Setter Property="BackgroundColor" Value="#024886" />
    <Setter Property="Margin">
      <OnPlatform x:TypeArguments="Thickness" iOS="0,5" />

Page Control

<Button Style="{StaticResource LoginButtonStyle}" />


Throws exception "StaticResource not found for key {x:Type Button}". This is how I remember doing it in WPF, but I'm assuming this isn't supported in Xamarin XAML.

Attempt 2: Inherit from common explicit style

Application ResourceDictionary

<Style x:Key="DefaultButtonStyle" TargetType="Button">
    <!-- Same as Attempt 1 -->
<!-- This implicit style causes issues with the inheritence of the Trigger in the above explicit style. When it's commented out, everything works fine. -->
<Style TargetType="Button" BasedOn="{StaticResource DefaultButtonStyle}" />

Page ResourceDictionary

<Style x:Key="LoginButtonStyle" TargetType="Button" BasedOn="{StaticResource DefaultButtonStyle}">
    <!-- Same as Attempt 1 -->

Page Control

Same as Attempt 1


Everything works except for the Trigger. However, when I remove the implicit style the Trigger magically starts working again. I'd rather not have to specify the explicit style on every Button, though. I believe this is just a bug, but I wanted to make sure before I take the time to prepare a bug report.

Any ideas?

Question on StackOverflow

Sign In or Register to comment.