Here is 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"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="App1.MainPage">
<BoxView>
<BoxView.BackgroundColor>
<OnPlatform x:TypeArguments="Color">
<On Platform="Android" Value="{Binding First}"></On>
<On Platform="iOS" Value="{Binding Second}"></On>
</OnPlatform>
</BoxView.BackgroundColor>
</BoxView>
</ContentPage>
Here is code-behind:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace App1
{
// Learn more about making custom code visible in the Xamarin.Forms previewer
// by visiting https://aka.ms/xamarinforms-previewer
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
this.BindingContext = this;
}
public Color First {
get {
return Color.FromHex("#575757");
}
}
public Color Second
{
get
{
return Color.FromHex("#ffffff");
}
}
}
}
After I ran the program, it reports an error: Specified cast is not valid.
What's the problem with it?

