3
votes

I have a Style with target type Grid. I want all Entry child elements within a grid of this style to automatically acquire a particular style.

I've had a look at these:

Styling nested elements in WPF

Apply Style to all child-elements of specific type

The only solution appears to be setting Resources within the parent Style, so this is what I've done:

<Style x:Key="BuggyGrid" TargetType="Grid">
    <!-- bunch of property setters -->
    <Style.Resources>
        <Style TargetType="Entry">
            <Setter Property="FontFamily" Value="Arial" />
        </Style>
    </Style.Resources>
</Style>

However, I get a build error: "No property, bindable property, or event found for 'Resources'".

Why do I get this error?

I'm using Xamarin.Forms 2.3.2.

1
You can't do that in Xamarin.Forms. That is for WPF. I'm not sure how would achieve nested styling in Xamarin.FormsSteve Chadbourne
@Steve Phew. You saved me hours of potential struggle. Maybe turn that into an answer so that I can accept it.Ash
And on a side note; "Arghh Xamarin".Ash
It certainly has its quirks!Steve Chadbourne

1 Answers

3
votes

The links you have referenced are specific to WPF XAML and do not apply to Xamarin.Forms XAML.

I'm not sure how you would achieve nested styles in Xamarin.Forms.

The only possibility is XamlCSS which I haven't personally used.

https://www.nuget.org/packages/XamlCSS.xamarinforms/2.0.0-pre1