我有以下C#代码:
var footer = new StackLayout()
{ BackgroundColor = Device.OnPlatform(Color.FromRgb(225, 240, 251), Color.FromRgb(225, 240, 251), Color.Black),
};
如何将其转换为Xamarin Xaml,更重要的是将其转换为FromRgb的设备平台细节?
到目前为止,我有以下XAML ......再次,这是让我感到困惑的FromRgb .
<StackLayout.BackgroundColor>
<Color>
<OnPlatform x:TypeArguments="Color"></OnPlatform>
</Color>
</StackLayout.BackgroundColor>
更新2015年2月14日
我刚刚尝试了下面的答案,我有以下内容,但它没有更新iOS或Windows Phone的背景颜色 . 如果我将背景颜色添加到根StackLayout元素,它可以工作......:
<StackLayout HorizontalOptions="FillAndExpand">
<StackLayout.BackgroundColor>
<Color>
<OnPlatform x:TypeArguments="Color">
<OnPlatform.WinPhone>#51C0D4</OnPlatform.WinPhone>
<OnPlatform.iOS>#51C0D4</OnPlatform.iOS>
</OnPlatform>
</Color>
</StackLayout.BackgroundColor>
<Label Text=""></Label>
<StackLayout Orientation="Horizontal" VerticalOptions="EndAndExpand" HorizontalOptions="FillAndExpand">
<StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand">
<Button Text="Login"></Button>
<Button Text="Sign Up"></Button>
</StackLayout>
</StackLayout>
</StackLayout>
2 回答
你快到了 . 默认转换器负责转换颜色来自命名颜色(例如白色,红色等)或十六进制颜色(例如:#FF0000) .
OnPlatform的较新版本语法略有不同
在Xaml中:
在代码中: