【发布时间】:2019-01-17 07:48:54
【问题描述】:
我以前使用 Xamarin.Forms 的 Frame 控件作为 Android 的 CardView,但我将 Xamarin.Forms 包更新到版本 3.1.0,并且框架外观发生了变化。它没有高程和阴影。我尝试创建自定义渲染器,但不起作用。
要解释我想说的话,请看下面的图片。第一张图片是框架的旧行为。外观与 Android 中的 CardView 完全相同,第二张图片是 Xamarin.Forms 版本 3.1.0 的新行为。框架没有高程和阴影。
旧行为:
新行为
这是我使用框架的代码(对于 Android 平台,CardView 是一个简单的框架)
<customViews:CardView>
<StackLayout Spacing="0">
<StackLayout.Margin>
<OnPlatform x:TypeArguments="Thickness" Android="16"/>
</StackLayout.Margin>
<ContentView>
<OnPlatform x:TypeArguments="View">
<OnPlatform.iOS>
<customViews:HeaderDivider/>
</OnPlatform.iOS>
</OnPlatform>
</ContentView>
public class CardView : Frame
{
public CardView()
{
Padding = 0;
if (Device.RuntimePlatform == Device.iOS)
{
HasShadow = false;
OutlineColor = Color.Transparent;
BackgroundColor = Color.Transparent;
}
}
}
【问题讨论】:
-
在代码中你写过什么吗?
-
@SrustiThakkar 在 Android 平台中,只是一个框架,属性有默认值。我将编辑问题以放置我的代码,您将看到“CardView”,但 CardView 继承自 Frame,并且仅针对 iOS 进行了更改。对于Android,只是一个Frame
-
你为什么不从 xaml 给它阴影和高程?
-
我认为没有必要像 CardView 那样创建自定义控件。你也可以直接使用Frame。
标签: xamarin xamarin.forms xamarin.android