public interface IScrollViewDependencyService
{
void Scrolling(bool isScrolling,object nativeObject);
}
public class ScrollViewExt : ScrollView
{
//Gets or sets the native scroll object
public object NativeObject { get; set; }
//Used to specify to enable/disable the scrolling
public bool IsScrolling { get; set; } = true;
} |
public MainPage()
{
InitializeComponent();
editor.ToolbarSettings.ToolbarItems.Add(new FooterToolbarItem()
{
Text = "Scroll"
});
editor.ToolbarSettings.ToolbarItemSelected += ToolbarSettings_ToolbarItemSelected;
}
private void ToolbarSettings_ToolbarItemSelected(object sender, ToolbarItemSelectedEventArgs e)
{
if (e.ToolbarItem.Text == "Scroll")
{
scrollView.IsScrolling = !scrollView.IsScrolling;
//Call the native method and pass the arguments
DependencyService.Get<IScrollViewDependencyService>().Scrolling(scrollView.IsScrolling, scrollView.NativeObject);
}
} |
public class CustomRenderer: ScrollViewRenderer
{
ScrollViewExt scrollViewExt;
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
scrollViewExt = e.NewElement as ScrollViewExt;
}
public override bool OnInterceptTouchEvent(MotionEvent ev)
{
//Cancelled scrolling b yreturn false
if (!scrollViewExt.IsScrolling)
return false;
return base.OnInterceptTouchEvent(ev);
}
}
public class CustomDependencyService : IScrollViewDependencyService
{
public void Scrolling(bool isScrolling, object nativeObject)
{
//No implementation needed for Android
}
}
|
public class CustomRenderer : ScrollViewRenderer
{
ScrollViewExt scrollViewExt;
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
scrollViewExt = e.NewElement as ScrollViewExt;
//Set native object
scrollViewExt.NativeObject = NativeView as UIScrollView;
}
}
public class CustomDependencyService : IScrollViewDependencyService
{
public void Scrolling(bool isScrolling, object nativeObject)
{
var native = nativeObject as UIScrollView;
//Disable the scrolling in native object
(nativeObject as UIScrollView).ScrollEnabled = isScrolling;
}
}
|
public class CustomRenderer : ScrollViewRenderer
{
ScrollViewExt scrollViewExt;
protected override void OnElementChanged(ElementChangedEventArgs<ScrollView> e)
{
base.OnElementChanged(e);
scrollViewExt = e.NewElement as ScrollViewExt;
//Set native object in the extended class variable
scrollViewExt.NativeObject = Control;
}
}
public class CustomDependencyService : IScrollViewDependencyService
{
public void Scrolling(bool isScrolling, object nativeObject)
{
var native = nativeObject as ScrollViewer;
//Enable/disable the scrolling option
if (isScrolling)
{
native.HorizontalScrollMode = Windows.UI.Xaml.Controls.ScrollMode.Enabled;
native.VerticalScrollMode = Windows.UI.Xaml.Controls.ScrollMode.Enabled;
}
else
{
native.HorizontalScrollMode = Windows.UI.Xaml.Controls.ScrollMode.Disabled;
native.VerticalScrollMode = Windows.UI.Xaml.Controls.ScrollMode.Disabled;
}
}
} |