Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin.forms Xamarin表单Listview和scrollview滚动条如何设置可见?_Xamarin.forms - Fatal编程技术网

Xamarin.forms Xamarin表单Listview和scrollview滚动条如何设置可见?

Xamarin.forms Xamarin表单Listview和scrollview滚动条如何设置可见?,xamarin.forms,Xamarin.forms,我正在使用xamarin表单应用程序(android目标) 视图包含一个滚动视图。 另一个视图包含listview 在这两种情况下,滚动效果都很好 问题在于,只有当用户用手指触摸屏幕时,滚动条才会在点击时出现。用户无法理解他必须滚动视图 我读了其他关于android原生版的帖子“ScrollView.setScrollbarFadingEnabled(false);” 在xamarain表单中找不到类似的属性或方法。。。 有没有办法达到同样的目标?您所指的“问题”是ListView滚动条的默认行

我正在使用xamarin表单应用程序(android目标)

视图包含一个滚动视图。 另一个视图包含listview

在这两种情况下,滚动效果都很好

问题在于,只有当用户用手指触摸屏幕时,滚动条才会在点击时出现。用户无法理解他必须滚动视图

我读了其他关于android原生版的帖子“ScrollView.setScrollbarFadingEnabled(false);”

在xamarain表单中找不到类似的属性或方法。。。
有没有办法达到同样的目标?

您所指的“问题”是ListView滚动条的默认行为,当屏幕上没有交互时,滚动条会隐藏/消失

您可以为每个平台创建自定义ListView渲染器:

在Android平台特定的自定义渲染器上:

Control.VerticalScrollbarEnabled = true;
Control.ScrollbarFadingEnabled = false;

作为@MalokuS答案的补充。下面是一个你可以尝试的例子

在共享/PCL项目中创建一个新类。此类将包含制作渲染器所需的可绑定属性

namespace YourProject.Views.CustomControls
{
#region CustomScrollview

public class CustomScrollView : ScrollView
{
    public static readonly BindableProperty IsHorizontalScrollbarEnabledProperty =
    BindableProperty.Create(
        nameof(IsHorizontalScrollbarEnabled),
        typeof(bool),
        typeof(CustomScrollView),
        true,
        BindingMode.Default,
        null);
    /// <summary>
    /// Gets or sets the Horizontal scrollbar visibility
    /// </summary>
    public bool IsHorizontalScrollbarEnabled
    {
        get { return (bool)GetValue(IsHorizontalScrollbarEnabledProperty); }
        set { SetValue(IsHorizontalScrollbarEnabledProperty, value); }
    }


    public static readonly BindableProperty IsVerticalScrollbarEnabledProperty =
    BindableProperty.Create(
        nameof(IsVerticalScrollbarEnabled),
        typeof(bool),
        typeof(BloopyScrollView),
        false,
        BindingMode.Default,
        null);
    /// <summary>
    /// Gets or sets the Vertical scrollbar visibility
    /// </summary>
    public bool IsVerticalScrollbarEnabled
    {
        get { return (bool)GetValue(IsVerticalScrollbarEnabledProperty); }
        set { SetValue(IsVerticalScrollbarEnabledProperty, value); }
    }
}

#endregion
}
之后,您可以在xaml文件中自由使用新控件:

 <CustomControls:CustomScrollView IsHorizontalScrollbarEnabled = "true"
                Orientation="Horizontal" HorizontalOptions="Fill" VerticalOptions="FillAndExpand">


希望有帮助!干杯

我参加聚会迟到了,但我遇到了与提问者相同的问题,多亏了Fedex,我才得以得到答案。这个答案是这个答案的延伸。您可以绑定类似于他所拥有的属性,也可以像下面这样对其进行硬编码,以使滚动条始终可见

class MyScrollViewRenderer : ScrollViewRenderer
    {
        public MyScrollViewRenderer(Context context) : base(context)
        {
        }

        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);
            if (Controller != null)
            {
                this.ScrollbarFadingEnabled = false;
            }
        }
    }

ScrollbarFadingEnabled=false导致我的应用程序在空对象引用上“尝试调用虚拟方法”android.widget.ScrollBarDrawable android.widget.ScrollBarDrawable.mutate()”崩溃
class MyScrollViewRenderer : ScrollViewRenderer
    {
        public MyScrollViewRenderer(Context context) : base(context)
        {
        }

        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);
            if (Controller != null)
            {
                this.ScrollbarFadingEnabled = false;
            }
        }
    }