我需要綁定字符串的背景顏色。 我的XAML代碼:在Xamarin Forms中綁定BackgroundColor屬性ContentPage
<?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>
我隱藏代碼:
...
public String ColorBackground { get; set; } = "#E40000";
...
我做的公共類()costructor之前設置此ColorBackground
。
但是不行......我在哪裏錯了?
感謝所有
我不認爲你可以綁定到'顏色'的字符串嘗試綁定到'顏色'屬性 – user1