This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity | |
{ | |
protected override void OnCreate(Bundle bundle) | |
{ | |
base.OnCreate(bundle); | |
global::Xamarin.Forms.Forms.Init(this, bundle); | |
Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init(); | |
LoadApplication(new App()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
async Task UpdateSelectedItem () | |
{ | |
await Task.Delay(300); | |
SelectedItem = SelectedIndex > -1 ? Children[SelectedIndex].BindingContext : null; | |
} | |
// ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class App : Application | |
{ | |
public IEnumerable<ICarouselViewModel> _pages; | |
public App() | |
{ | |
_pages = new List<ICarouselViewModel>() | |
{ | |
new PageOneViewModel(), | |
new PageTwoViewModel() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public HomePage(CarouselLayout.IndicatorStyleEnum indicatorStyle) | |
{ | |
_indicatorStyle = indicatorStyle; | |
viewModel = new SwitcherPageViewModel(); | |
BindingContext = viewModel; | |
Title = _indicatorStyle.ToString(); | |
relativeLayout = new RelativeLayout |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ItemsSourceChanged () | |
{ | |
if (ItemsSource == null) return; | |
CreateTabs(); | |
} | |
void CreateTabs() | |
{ | |
if(Children != null && Children.Count > 0) Children.Clear(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ItemsSourceChanged () | |
{ | |
if (ItemsSource == null) return; | |
var countDelta = ItemsSource.Count - Children.Count; | |
if (countDelta > 0) { | |
for (var i = 0; i < countDelta; i++) | |
{ | |
CreateDot(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum IndicatorStyleEnum | |
{ | |
None, | |
Dots, | |
Tabs | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 (); | |
} |