Skip to content

Instantly share code, notes, and snippets.

public class FloatingActionButtonView : View
{
public static readonly BindableProperty ImageNameProperty = BindableProperty.Create<FloatingActionButtonView,string>( p => p.ImageName, string.Empty);
public string ImageName
{
get { return (string)GetValue (ImageNameProperty); }
set { SetValue (ImageNameProperty, value); }
}
public static readonly BindableProperty ColorNormalProperty = BindableProperty.Create<FloatingActionButtonView,Color>( p => p.ColorNormal, Color.White);
public enum FloatingActionButtonSize
{
Normal,
Mini
}
public class FloatingActionButtonViewRenderer : ViewRenderer<FloatingActionButtonView, FrameLayout>
{
...
private readonly Android.Content.Context context;
private readonly FloatingActionButton fab;
public FloatingActionButtonViewRenderer()
{
context = Xamarin.Forms.Forms.Context;
fab = new FloatingActionButton(context);
public class MainPage : ContentPage
{
public MainPage()
{
var fab = new FloatingActionButtonView() {
ImageName = "ic_add.png",
ColorNormal = Color.FromHex("ff3498db"),
ColorPressed = Color.Black,
ColorRipple = Color.FromHex("ff3498db")
};
public class CarouselLayout : ScrollView
{
public enum IndicatorStyleEnum
{
None,
Dots,
Tabs
}
readonly StackLayout _stack;
public static readonly BindableProperty ItemsSourceProperty =
BindableProperty.Create<CarouselLayout, IList> (
view => view.ItemsSource,
null,
propertyChanging: (bindableObject, oldValue, newValue) => {
((CarouselLayout)bindableObject).ItemsSourceChanging ();
},
propertyChanged: (bindableObject, oldValue, newValue) => {
((CarouselLayout)bindableObject).ItemsSourceChanged ();
}
void SnapScroll ()
{
var roughIndex = (float)_scrollView.ScrollX / _scrollView.Width;
var targetIndex =
_deltaX < 0 ? Math.Floor (roughIndex)
: _deltaX > 0 ? Math.Ceil (roughIndex)
: Math.Round (roughIndex);
ScrollToIndex ((int)targetIndex);
void NativeScrolled (object sender, EventArgs e)
{
var center = _native.ContentOffset.X + (_native.Bounds.Width / 2);
((CarouselLayout)Element).SelectedIndex = ((int)center) / ((int)_native.Bounds.Width);
}
void ElementPropertyChanged(object sender, PropertyChangedEventArgs e) {
if (e.PropertyName == CarouselLayout.SelectedIndexProperty.PropertyName && !Dragging) {
ScrollToSelection (false);
}
public enum IndicatorStyleEnum
{
None,
Dots,
Tabs
}
void ItemsSourceChanged ()
{
if (ItemsSource == null) return;
var countDelta = ItemsSource.Count - Children.Count;
if (countDelta > 0) {
for (var i = 0; i < countDelta; i++)
{
CreateDot();