Xamarin形式框架阴影设计 [英] Xamarin Forms Frame Shadow Design

查看:324
本文介绍了Xamarin形式框架阴影设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有列表的Xamarin内容页面.对于ListItem,我想要类似于Android中的cardview.

I have an Xamarin Content Page with a List. For the ListItems I want something similar to the cardview in Android.

基于我发现框架可以实现的目标.我有以下代码:

Base on what I found that could be accomplished by a Frame. I have this code:

<ViewCell>
    <StackLayout Padding="8" >
        <controls:CardView HasShadow="True" OutlineColor="LightGray">
            <StackLayout Orientation="Vertical" Padding="5">
                // Some labels and Buttons                
            </StackLayout>
        </Frame>
    </StackLayout>
</ViewCell>

CardView具有以下代码:

The CardView has the following code:

public class CardView : Frame
{
    public CardView()
    {
        Padding = 0;
        if (Device.RuntimePlatform == Device.iOS)
        {
            HasShadow = false;
            OutlineColor = Color.Transparent;
            BackgroundColor = Color.Transparent;
        }
    }
}

结果是这样的:

与这张卡的悬浮效果相比,它看起来更像是边框. 上面的示例实际上使用相同的cardview控件,没有任何样式(即使没有OutlineColor).我会错过必须配置的选项吗?或者我如何获得与样本中相同的结果?

This looks more like a Border than this card levitation effect. The example above actually uses the same cardview control, without any styles (even without the OutlineColor). Do I miss a option I have to configure? Or how could I achieve the same result as in the sample?

Xamarin.Forms版本:2.5.0.280555

Xamarin.Forms Version: 2.5.0.280555

推荐答案

我已经实现了一些非常相似的东西(Frame作为要在堆栈视图中显示的卡片).不幸的是,我不能共享确切的代码,因为不是我拥有它,而是我的老板,但是我可以告诉您如何实现.

I have implemented something very similar (also Frames as cards to be displayed in a stack view). Unfortunately I can't share the exact code, for it's not me owning it, but my employer, but I can tell you how to achieve this.

我向CardView添加了属性ShadowRadius,并创建了一个自Xamarin.Forms.Platform.Android.AppCompat.FrameRenderer派生的自定义渲染器.在渲染器中,我设置渲染器的Elevation

I have added a property ShadowRadius to CardView and created a custom renderer, derived from Xamarin.Forms.Platform.Android.AppCompat.FrameRenderer. In the renderer I am setting the Elevation of the renderer

protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
{
    /* ... */

    this.Elevation = ((CardView)e.NewElement).ShadowRadius;
}

我的卡片在Xamarin.Forms 2.5.0.280555上显示了很好的高程阴影.

My cards are showing a nice elevation shadow with Xamarin.Forms 2.5.0.280555.

这篇关于Xamarin形式框架阴影设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆