Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Custom Renderer not compiling

$
0
0

I want my ListView to always display the scrollbar, and then I want to specify the width of the scrollbar (the next stage).
So I have been advised this can be done by using a custom renderer.
It looks like this is simple and it probably is but I cant get it to compile.
I am working with Android first, and then iOS and UWP.
As there are no bindable properties needed, the new ListViewScrollBar control is simple enough;
using Xamarin.Forms;

        namespace Sir.Mobile.CustomRenderers
        {
            public class ListViewScrollBar : ListView
            {
                public ListViewScrollBar()
                {
                }
            }
        }

And then in my Android project;
using Android.Content;
using Sir.Mobile.CustomRenderers;
using Sir.Mobile.Droid.CustomRenderers;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

    [assembly: ExportRenderer(typeof(ListViewScrollBar), typeof(ListViewScrollBarRenderer))]

    namespace Sir.Mobile.Droid.CustomRenderers
    {
        /// <inheritdoc />
        public class ListViewScrollBarRenderer : ListViewRenderer
        {
            public ListViewScrollBarRenderer(Context context) : base(context)
            {
                if (Control == null)
                {
                    return;
                }

                Control.VerticalScrollBarEnabled = true;
            }
        }
    }

I have not created a similar class for my iOS and UWP projects yet.
However this ListViewScrollBar control is not being picked up in my XAML;

    <?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:Control="clr-namespace:Xamstrap;assembly=Xamstrap"
                 xmlns:Attached="clr-namespace:Xamstrap.AttachedProperties;assembly=Xamstrap"
                 xmlns:b="clr-namespace:Prism.Behaviors;assembly=Prism.Forms"
                 xmlns:c="clr-namespace:Sir.Mobile.CustomRenderers;assembly=Sir.Mobile.CustomRenderers"
                 x:Class="Sir.Mobile.Views.ListProperties"
                 ControlTemplate="{StaticResource MainHeader}"
                 Title="Select a Property">
    ...
    <c:ListViewScrollBar ItemsSource="{Binding PropertyList}">
                            <c:ListView.Behaviors>
                                <b:EventToCommandBehavior Command="{Binding ItemTappedCommand}"
                                                      EventName="ItemTapped"
                                                      EventArgsParameterPath="Item" />
                            </c:ListView.Behaviors>
                            <c:ListView.ItemTemplate>
                                <DataTemplate>
                                    <ViewCell>
                                        <ContentView  Padding="3">
                                            <Label Text="{Binding FullAddress}" BackgroundColor="blue" TextColor="White" FontSize="7"
                                               VerticalTextAlignment="Center" HorizontalTextAlignment="Center" />
                                        </ContentView>
                                    </ViewCell>
                                </DataTemplate>
                            </c:ListView.ItemTemplate>
                        </c:ListViewScrollBar>
    

So what is the problem here?


Viewing all articles
Browse latest Browse all 77050

Trending Articles