在Visual Studio for Mac上。这是我的XAML:
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns ="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="WontSetBackgroundColor">
<ContentView x:Name="subView"/>
</ContentView>
这是我后面的代码:
using Xamarin.Forms;
namespace MyProject
{
public partial class WontSetBackgroundColor : ContentView
{
public WontSetBackgroundColor()
{
InitializeComponent();
subView.BackgroundColor = Color.Teal;
}
}
}
预览窗口不显示蓝绿色。但是,如果我在XAML中设置背景颜色,就像这样:
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns ="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="WontSetBackgroundColor">
<ContentView x:Name="subView" BackgroundColor="Teal"/>
</ContentView>
预览窗口确实显示蓝绿色。
有帮助吗?