Sta*_*tam 10 xamarin.android mvvmcross xamarin.forms
目前我正在使用MvvmCross开发Xamarin Forms Android项目.关于Frame我有一个奇怪的问题.每当我设置OutlineColor时,它仅在iOS中显示,而不在Android中显示.我已尝试使用不同的Xamarin Forms项目,并且两个平台都显示它没有任何问题.我没有任何迹象表明为什么会这样.MvvmCross能否以某种方式与此问题相关?
这是一个示例:
<core:BasePage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:core="clr-namespace:Core.Base.Views;assembly=Core"
x:Class="Views.TestPage"
BackgroundImage="background_secret.png"
Title="Test">
<ContentPage.Content>
<Grid
HorizontalOptions="FillAndExpand"
Padding="12,20,12,20"
VerticalOptions="FillAndExpand">
<Frame
HasShadow="false"
VerticalOptions="Fill"
BackgroundColor="White"
OutlineColor="#1961ac">
<StackLayout>
<Frame
VerticalOptions="Start"
Padding="8,4,8,4"
HasShadow="false"
OutlineColor="#9DB0BB">
<Label Text="Test"></Label>
</Frame>
</StackLayout>
</Frame>
</Grid>
</ContentPage.Content>
</core:BasePage>
Run Code Online (Sandbox Code Playgroud)
Xamarin Forms版本2.1 MvvmCross版本4.1
即使我有同样的问题,为了解决这个问题,我已经为Frame控件添加了自定义渲染器.在framerenderer中需要重写方法Draw和私有方法DrawOutline如下,
public override void Draw(ACanvas canvas)
{
base.Draw(canvas);
DrawOutline(canvas, canvas.Width, canvas.Height, 4f);//set corner radius
}
void DrawOutline(ACanvas canvas, int width, int height, float cornerRadius)
{
using (var paint = new Paint { AntiAlias = true })
using (var path = new Path())
using (Path.Direction direction = Path.Direction.Cw)
using (Paint.Style style = Paint.Style.Stroke)
using (var rect = new RectF(0, 0, width, height))
{
float rx = Forms.Context.ToPixels(cornerRadius);
float ry = Forms.Context.ToPixels(cornerRadius);
path.AddRoundRect(rect, rx, ry, direction);
paint.StrokeWidth = 2f; //set outline stroke
paint.SetStyle(style);
paint.Color = Color.ParseColor("#A7AE22");//set outline color //_frame.OutlineColor.ToAndroid();
canvas.DrawPath(path, paint);
}
}
Run Code Online (Sandbox Code Playgroud)
在另一种方法中,您还可以考虑使用圆角的android选择器xml作为后台资源.有关此更多详细信息,请查看我的博客文章:http://www.appliedcodelog.com/2016/11/xamarin-form-frame-outline-color_21.html
| 归档时间: |
|
| 查看次数: |
2820 次 |
| 最近记录: |