我需要将背景颜色绑定到字符串。
我的XAML代码:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Fimap.LoadingPage"
BackgroundColor="{Binding ColorBackground}">
<ContentPage.Content>
<Grid Padding="130" x:Name="griglia">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="10*"></RowDefinition>
<RowDefinition Height="40*"></RowDefinition>
<RowDefinition Height="25*"></RowDefinition>
<RowDefinition Height="25*"></RowDefinition>
</Grid.RowDefinitions>
<Image Source="logo.png" Grid.Row="1"></Image>
<ActivityIndicator x:Name="loading" Grid.Row="2" IsVisible="true" Color="{Binding ColorBackground}" IsRunning="true" />
</Grid>
</ContentPage.Content>
</ContentPage>
我的codebehind代码:
...
public String ColorBackground { get; set; } = "#E40000";
...
我在public Class()构造函数之前设置了ColorBackground
,但它没有生效...我错在哪里了?
谢谢大家
string
绑定到Color
,请尝试将其绑定到一个Color
属性。 - JKennedy