【发布时间】:2020-09-19 18:33:28
【问题描述】:
这里是 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>
这里是代码隐藏:
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");
}
}
}
}
我运行程序后,报错: 指定的演员表无效。
它有什么问题?
【问题讨论】:
-
@MihailDuchev 不,不一样。如果我从 Color.FromHex("#575757"); 修改代码返回 Color.Red; .它运行成功,没有任何错误。
-
我刚刚尝试将
Second更改为返回 Color.Green,但它会因同样的错误而崩溃。 -
好吧,这是我的错。我只是按照你说的做了,结果证明是真的崩溃了。顺便说一句,在您上面提供的文章中,这是一个已在 2017.01.24 修复的错误。为什么我又遇到了,竟然用最新版的Xamarin.Forms? @MihailDuchev
-
是的,我的错,我很快就读完了。我会看看这个。
标签: xamarin xamarin.forms