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

How to bind a Layout's background color in ControlTemplate

$
0
0

The StackLayout in my ControlTemplage:

<StackLayout Grid.Row="0" Grid.Column="0" Style="{StaticResource NavigationBarLayoutStyle}" BackgroundColor="TemplateBinding Parent.HomeBackgroundColor"> ...... </StackLayout>

I want to change its background color in the behind code of Home page by using a bindable property

public static readonly BindableProperty HomeBackgroundColorProperty = BindableProperty.Create("HomeBackgroundColor", typeof(Color), typeof(HomePage), Color.Red); public Color HomeBackgroundColor { get { return (Color)GetValue(HomeBackgroundColorProperty); } }

The error message is
System.InvalidOperationException: Cannot convert "TemplateBinding Parent.HomeBackgroundColor" into Xamarin.Forms.Color

The same way works very well for Label.Text property but the background color. Thanks for your help


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>