【发布时间】:2020-12-03 12:09:19
【问题描述】:
尝试更改ScrollView 栏的颜色。我在这里找到了这个链接,但我更喜欢编写一个自定义渲染器,就像我使用所有其他控件一样:
Color of ScrollBar in ScrollView
问题是,我找不到任何对条形颜色有任何影响的属性/方法。到目前为止,这是我的尝试:
public class CustomScrollRenderer : ScrollViewRenderer
{
public CustomScrollRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
this.ScrollBarSize = 50;
this.ScrollBarDefaultDelayBeforeFade = 60000;
this.SetBackgroundColor(Android.Graphics.Color.Red);
this.SetOutlineAmbientShadowColor(Android.Graphics.Color.Red);
this.SetOutlineSpotShadowColor(Android.Graphics.Color.Red);
}
}
【问题讨论】:
-
为什么要创建自定义渲染只是为了更改属性而可以实现自定义效果?这是一个矫枉过正。 why-use-an-effect-over-a-custom-renderer
-
我还在更改条形宽度和淡入淡出时间。该控件已经分散在我的 Xaml 中。不管是否矫枉过正,在我的自定义渲染器中更改颜色属性会非常方便。
标签: c# xamarin xamarin.forms custom-renderer