├── segmented-control.gif ├── iOS ├── Assets.xcassets │ ├── Contents.json │ └── AppIcon.appiconset │ │ └── Contents.json ├── packages.config ├── Entitlements.plist ├── Main.cs ├── AppDelegate.cs ├── Renderers │ └── ScrollViewWithNotBarRenderer.cs ├── LaunchScreen.storyboard ├── Info.plist └── SegmentedControlSample.iOS.csproj ├── Droid ├── Resources │ ├── drawable │ │ └── icon.png │ ├── drawable-hdpi │ │ └── icon.png │ ├── drawable-xhdpi │ │ └── icon.png │ ├── drawable-xxhdpi │ │ └── icon.png │ ├── layout │ │ ├── Toolbar.axml │ │ └── Tabbar.axml │ ├── values │ │ └── styles.xml │ └── AboutResources.txt ├── Properties │ ├── AndroidManifest.xml │ └── AssemblyInfo.cs ├── Assets │ └── AboutAssets.txt ├── MainActivity.cs ├── packages.config ├── Renderers │ └── ScrollViewWithNotBarRenderer.cs └── SegmentedControlSample.Droid.csproj ├── SegmentedControlSample ├── packages.config ├── Controls │ ├── NoScrolleableScrollView.cs │ └── SegmentedBarControl.cs ├── App.xaml ├── SegmentedControlSamplePage.xaml.cs ├── App.xaml.cs ├── SegmentedControlSamplePage.xaml ├── Properties │ └── AssemblyInfo.cs └── SegmentedControlSample.csproj ├── README.md ├── .gitignore ├── LICENSE └── SegmentedControlSample.sln /segmented-control.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CrossGeeks/SegmentedControlSample/HEAD/segmented-control.gif -------------------------------------------------------------------------------- /iOS/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Droid/Resources/drawable/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CrossGeeks/SegmentedControlSample/HEAD/Droid/Resources/drawable/icon.png -------------------------------------------------------------------------------- /Droid/Resources/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CrossGeeks/SegmentedControlSample/HEAD/Droid/Resources/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /Droid/Resources/drawable-xhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CrossGeeks/SegmentedControlSample/HEAD/Droid/Resources/drawable-xhdpi/icon.png -------------------------------------------------------------------------------- /Droid/Resources/drawable-xxhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CrossGeeks/SegmentedControlSample/HEAD/Droid/Resources/drawable-xxhdpi/icon.png -------------------------------------------------------------------------------- /iOS/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /SegmentedControlSample/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /SegmentedControlSample/Controls/NoScrolleableScrollView.cs: -------------------------------------------------------------------------------- 1 | using Xamarin.Forms; 2 | 3 | namespace SegmentedControlSample.Controls 4 | { 5 | public class ScrollViewWithNotBar : ScrollView 6 | { 7 | 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /iOS/Entitlements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /SegmentedControlSample/App.xaml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Droid/Properties/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SegmentedControlSample 2 | 3 |

4 | 5 |

6 | 7 | Blog post: [http://www.xamboy.com/2018/01/12/segmented-bar-control-in-xamarin-forms/](http://www.xamboy.com/2018/01/12/segmented-bar-control-in-xamarin-forms/) 8 | -------------------------------------------------------------------------------- /Droid/Resources/layout/Toolbar.axml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /Droid/Resources/layout/Tabbar.axml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /iOS/Main.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | using Foundation; 6 | using UIKit; 7 | 8 | namespace SegmentedControlSample.iOS 9 | { 10 | public class Application 11 | { 12 | // This is the main entry point of the application. 13 | static void Main(string[] args) 14 | { 15 | // if you want to use a different Application Delegate class from "AppDelegate" 16 | // you can specify it here. 17 | UIApplication.Main(args, null, "AppDelegate"); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /iOS/AppDelegate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | using Foundation; 6 | using UIKit; 7 | 8 | namespace SegmentedControlSample.iOS 9 | { 10 | [Register("AppDelegate")] 11 | public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate 12 | { 13 | public override bool FinishedLaunching(UIApplication app, NSDictionary options) 14 | { 15 | global::Xamarin.Forms.Forms.Init(); 16 | 17 | LoadApplication(new App()); 18 | 19 | return base.FinishedLaunching(app, options); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Xamarin stuff 2 | Components 3 | [Pp]ackages 4 | *.userprefs 5 | Resource.designer.cs 6 | 7 | #Autosave files 8 | *~ 9 | 10 | #build 11 | [Oo]bj/ 12 | [Bb]in/ 13 | packages/ 14 | TestResults/ 15 | 16 | # globs 17 | Makefile.in 18 | *.DS_Store 19 | *.sln.cache 20 | *.suo 21 | *.cache 22 | *.pidb 23 | *.userprefs 24 | *.usertasks 25 | config.log 26 | config.make 27 | config.status 28 | aclocal.m4 29 | install-sh 30 | autom4te.cache/ 31 | *.user 32 | *.tar.gz 33 | tarballs/ 34 | test-results/ 35 | Thumbs.db 36 | 37 | #Mac bundle stuff 38 | *.dmg 39 | *.app 40 | 41 | #resharper 42 | *_Resharper.* 43 | *.Resharper 44 | 45 | #dotCover 46 | *.dotCover 47 | -------------------------------------------------------------------------------- /Droid/Assets/AboutAssets.txt: -------------------------------------------------------------------------------- 1 | Any raw assets you want to be deployed with your application can be placed in 2 | this directory (and child directories) and given a Build Action of "AndroidAsset". 3 | 4 | These files will be deployed with your package and will be accessible using Android's 5 | AssetManager, like this: 6 | 7 | public class ReadAsset : Activity 8 | { 9 | protected override void OnCreate (Bundle bundle) 10 | { 11 | base.OnCreate (bundle); 12 | 13 | InputStream input = Assets.Open ("my_asset.txt"); 14 | } 15 | } 16 | 17 | Additionally, some Android functions will automatically load asset files: 18 | 19 | Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf"); 20 | -------------------------------------------------------------------------------- /SegmentedControlSample/SegmentedControlSamplePage.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics; 3 | using Xamarin.Forms; 4 | 5 | namespace SegmentedControlSample 6 | { 7 | public partial class SegmentedControlSamplePage : ContentPage 8 | { 9 | public SegmentedControlSamplePage() 10 | { 11 | InitializeComponent(); 12 | var vehicleTypes = new List() { "Motocycle", "Car", "Plane", "Boat", "Bike", "Jeep", "Train", "Truck" }; 13 | segment.Children = vehicleTypes; 14 | } 15 | 16 | void Handle_SelectedItemChanged(object sender, SelectedItemChangedEventArgs e) 17 | { 18 | ItemSelectedText.Text = $"{e.SelectedItem}"; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /SegmentedControlSample/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using Xamarin.Forms; 2 | 3 | namespace SegmentedControlSample 4 | { 5 | public partial class App : Application 6 | { 7 | public App() 8 | { 9 | InitializeComponent(); 10 | 11 | MainPage = new NavigationPage(new SegmentedControlSamplePage(){Title="Segmented Control Sample"}){BarBackgroundColor=Color.DarkGray, BarTextColor=Color.White}; 12 | } 13 | 14 | protected override void OnStart() 15 | { 16 | // Handle when your app starts 17 | } 18 | 19 | protected override void OnSleep() 20 | { 21 | // Handle when your app sleeps 22 | } 23 | 24 | protected override void OnResume() 25 | { 26 | // Handle when your app resumes 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Droid/MainActivity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Android.App; 4 | using Android.Content; 5 | using Android.Content.PM; 6 | using Android.Runtime; 7 | using Android.Views; 8 | using Android.Widget; 9 | using Android.OS; 10 | 11 | namespace SegmentedControlSample.Droid 12 | { 13 | [Activity(Label = "SegmentedControlSample.Droid", Icon = "@drawable/icon", Theme = "@style/MyTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] 14 | public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity 15 | { 16 | protected override void OnCreate(Bundle bundle) 17 | { 18 | TabLayoutResource = Resource.Layout.Tabbar; 19 | ToolbarResource = Resource.Layout.Toolbar; 20 | 21 | base.OnCreate(bundle); 22 | 23 | global::Xamarin.Forms.Forms.Init(this, bundle); 24 | 25 | LoadApplication(new App()); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Droid/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /SegmentedControlSample/SegmentedControlSamplePage.xaml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 14 | 15 | 21 | 22 | -------------------------------------------------------------------------------- /Droid/Renderers/ScrollViewWithNotBarRenderer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using SegmentedControlSample.Controls; 4 | using SegmentedControlSample.Droid.Renderers; 5 | using Xamarin.Forms; 6 | using Xamarin.Forms.Platform.Android; 7 | 8 | [assembly: ExportRenderer(typeof(ScrollViewWithNotBar),typeof(ScrollViewWithNotBarRenderer))] 9 | namespace SegmentedControlSample.Droid.Renderers 10 | { 11 | public class ScrollViewWithNotBarRenderer : ScrollViewRenderer 12 | { 13 | protected override void OnElementChanged(VisualElementChangedEventArgs e) 14 | { 15 | base.OnElementChanged(e); 16 | 17 | if (e.OldElement != null || this.Element == null) 18 | return; 19 | 20 | if (e.OldElement != null) 21 | e.OldElement.PropertyChanged -= OnElementPropertyChanged; 22 | 23 | e.NewElement.PropertyChanged += OnElementPropertyChanged; 24 | 25 | } 26 | 27 | protected void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) 28 | { 29 | this.HorizontalScrollBarEnabled = false; 30 | this.VerticalScrollBarEnabled = false; 31 | 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Rendy Del Rosario 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /SegmentedControlSample/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // Information about this assembly is defined by the following attributes. 5 | // Change them to the values specific to your project. 6 | 7 | [assembly: AssemblyTitle("SegmentedControlSample")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("")] 12 | [assembly: AssemblyCopyright("(c) Rendy Del Rosario")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 17 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 18 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 19 | 20 | [assembly: AssemblyVersion("1.0.*")] 21 | 22 | // The following attributes are used to specify the signing key for the assembly, 23 | // if desired. See the Mono documentation for more information about signing. 24 | 25 | //[assembly: AssemblyDelaySign(false)] 26 | //[assembly: AssemblyKeyFile("")] 27 | -------------------------------------------------------------------------------- /Droid/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using Android.App; 4 | 5 | // Information about this assembly is defined by the following attributes. 6 | // Change them to the values specific to your project. 7 | 8 | [assembly: AssemblyTitle("SegmentedControlSample.Droid")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("")] 13 | [assembly: AssemblyCopyright("(c) Rendy Del Rosario")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 18 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 19 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 20 | 21 | [assembly: AssemblyVersion("1.0.0")] 22 | 23 | // The following attributes are used to specify the signing key for the assembly, 24 | // if desired. See the Mono documentation for more information about signing. 25 | 26 | //[assembly: AssemblyDelaySign(false)] 27 | //[assembly: AssemblyKeyFile("")] 28 | -------------------------------------------------------------------------------- /iOS/Renderers/ScrollViewWithNotBarRenderer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using SegmentedControlSample.Controls; 4 | using SegmentedControlSample.iOS.Renderers; 5 | using Xamarin.Forms; 6 | using Xamarin.Forms.Platform.iOS; 7 | 8 | [assembly: ExportRenderer(typeof(ScrollViewWithNotBar),typeof(ScrollViewWithNotBarRenderer))] 9 | namespace SegmentedControlSample.iOS.Renderers 10 | { 11 | public class ScrollViewWithNotBarRenderer : ScrollViewRenderer 12 | { 13 | protected override void OnElementChanged(VisualElementChangedEventArgs e) 14 | { 15 | base.OnElementChanged(e); 16 | 17 | if (e.OldElement != null || this.Element == null) 18 | { 19 | return; 20 | } 21 | 22 | if (e.OldElement != null) 23 | { 24 | e.OldElement.PropertyChanged -= OnElementPropertyChanged; 25 | } 26 | 27 | e.NewElement.PropertyChanged += OnElementPropertyChanged; 28 | } 29 | 30 | private void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) 31 | { 32 | this.ShowsHorizontalScrollIndicator = false; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Droid/Resources/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 24 | 27 | 28 | -------------------------------------------------------------------------------- /iOS/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /iOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDisplayName 6 | SegmentedControlSample 7 | CFBundleName 8 | SegmentedControlSample 9 | CFBundleIdentifier 10 | com.samples.SegmentedControlSample 11 | CFBundleShortVersionString 12 | 1.0 13 | CFBundleVersion 14 | 1.0 15 | LSRequiresIPhoneOS 16 | 17 | MinimumOSVersion 18 | 8.0 19 | UIDeviceFamily 20 | 21 | 1 22 | 2 23 | 24 | UILaunchStoryboardName 25 | LaunchScreen 26 | UIRequiredDeviceCapabilities 27 | 28 | armv7 29 | 30 | UISupportedInterfaceOrientations 31 | 32 | UIInterfaceOrientationPortrait 33 | UIInterfaceOrientationLandscapeLeft 34 | UIInterfaceOrientationLandscapeRight 35 | 36 | UISupportedInterfaceOrientations~ipad 37 | 38 | UIInterfaceOrientationPortrait 39 | UIInterfaceOrientationPortraitUpsideDown 40 | UIInterfaceOrientationLandscapeLeft 41 | UIInterfaceOrientationLandscapeRight 42 | 43 | XSAppIconAssets 44 | Assets.xcassets/AppIcon.appiconset 45 | 46 | 47 | -------------------------------------------------------------------------------- /Droid/Resources/AboutResources.txt: -------------------------------------------------------------------------------- 1 | Images, layout descriptions, binary blobs and string dictionaries can be included 2 | in your application as resource files. Various Android APIs are designed to 3 | operate on the resource IDs instead of dealing with images, strings or binary blobs 4 | directly. 5 | 6 | For example, a sample Android app that contains a user interface layout (main.axml), 7 | an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png) 8 | would keep its resources in the "Resources" directory of the application: 9 | 10 | Resources/ 11 | drawable/ 12 | icon.png 13 | 14 | layout/ 15 | main.axml 16 | 17 | values/ 18 | strings.xml 19 | 20 | In order to get the build system to recognize Android resources, set the build action to 21 | "AndroidResource". The native Android APIs do not operate directly with filenames, but 22 | instead operate on resource IDs. When you compile an Android application that uses resources, 23 | the build system will package the resources for distribution and generate a class called "R" 24 | (this is an Android convention) that contains the tokens for each one of the resources 25 | included. For example, for the above Resources layout, this is what the R class would expose: 26 | 27 | public class R { 28 | public class drawable { 29 | public const int icon = 0x123; 30 | } 31 | 32 | public class layout { 33 | public const int main = 0x456; 34 | } 35 | 36 | public class strings { 37 | public const int first_string = 0xabc; 38 | public const int second_string = 0xbcd; 39 | } 40 | } 41 | 42 | You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main 43 | to reference the layout/main.axml file, or R.strings.first_string to reference the first 44 | string in the dictionary file values/strings.xml. 45 | -------------------------------------------------------------------------------- /SegmentedControlSample/SegmentedControlSample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | {4F5F7BA1-FEE0-44E0-870D-0377510AEB09} 7 | {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 8 | true 9 | Library 10 | SegmentedControlSample 11 | SegmentedControlSample 12 | v4.5 13 | Profile111 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug 20 | DEBUG; 21 | prompt 22 | 4 23 | 24 | 25 | true 26 | bin\Release 27 | prompt 28 | 4 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | App.xaml 37 | 38 | 39 | SegmentedControlSamplePage.xaml 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | ..\packages\Xamarin.Forms.2.3.4.247\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.Core.dll 48 | 49 | 50 | ..\packages\Xamarin.Forms.2.3.4.247\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.Platform.dll 51 | 52 | 53 | ..\packages\Xamarin.Forms.2.3.4.247\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.Xaml.dll 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /iOS/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | }, 93 | { 94 | "size" : "24x24", 95 | "idiom" : "watch", 96 | "scale" : "2x", 97 | "role" : "notificationCenter", 98 | "subtype" : "38mm" 99 | }, 100 | { 101 | "size" : "27.5x27.5", 102 | "idiom" : "watch", 103 | "scale" : "2x", 104 | "role" : "notificationCenter", 105 | "subtype" : "42mm" 106 | }, 107 | { 108 | "size" : "29x29", 109 | "idiom" : "watch", 110 | "role" : "companionSettings", 111 | "scale" : "2x" 112 | }, 113 | { 114 | "size" : "29x29", 115 | "idiom" : "watch", 116 | "role" : "companionSettings", 117 | "scale" : "3x" 118 | }, 119 | { 120 | "size" : "40x40", 121 | "idiom" : "watch", 122 | "scale" : "2x", 123 | "role" : "appLauncher", 124 | "subtype" : "38mm" 125 | }, 126 | { 127 | "size" : "44x44", 128 | "idiom" : "watch", 129 | "scale" : "2x", 130 | "role" : "longLook", 131 | "subtype" : "42mm" 132 | }, 133 | { 134 | "size" : "86x86", 135 | "idiom" : "watch", 136 | "scale" : "2x", 137 | "role" : "quickLook", 138 | "subtype" : "38mm" 139 | }, 140 | { 141 | "size" : "98x98", 142 | "idiom" : "watch", 143 | "scale" : "2x", 144 | "role" : "quickLook", 145 | "subtype" : "42mm" 146 | }, 147 | { 148 | "idiom" : "mac", 149 | "size" : "16x16", 150 | "scale" : "1x" 151 | }, 152 | { 153 | "idiom" : "mac", 154 | "size" : "16x16", 155 | "scale" : "2x" 156 | }, 157 | { 158 | "idiom" : "mac", 159 | "size" : "32x32", 160 | "scale" : "1x" 161 | }, 162 | { 163 | "idiom" : "mac", 164 | "size" : "32x32", 165 | "scale" : "2x" 166 | }, 167 | { 168 | "idiom" : "mac", 169 | "size" : "128x128", 170 | "scale" : "1x" 171 | }, 172 | { 173 | "idiom" : "mac", 174 | "size" : "128x128", 175 | "scale" : "2x" 176 | }, 177 | { 178 | "idiom" : "mac", 179 | "size" : "256x256", 180 | "scale" : "1x" 181 | }, 182 | { 183 | "idiom" : "mac", 184 | "size" : "256x256", 185 | "scale" : "2x" 186 | }, 187 | { 188 | "idiom" : "mac", 189 | "size" : "512x512", 190 | "scale" : "1x" 191 | }, 192 | { 193 | "idiom" : "mac", 194 | "size" : "512x512", 195 | "scale" : "2x" 196 | } 197 | ], 198 | "info" : { 199 | "version" : 1, 200 | "author" : "xcode" 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /SegmentedControlSample.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio 15 3 | VisualStudioVersion = 15.0.27130.2010 4 | MinimumVisualStudioVersion = 10.0.40219.1 5 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SegmentedControlSample", "SegmentedControlSample\SegmentedControlSample.csproj", "{4F5F7BA1-FEE0-44E0-870D-0377510AEB09}" 6 | EndProject 7 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SegmentedControlSample.iOS", "iOS\SegmentedControlSample.iOS.csproj", "{D76C5B18-720E-4D94-AAD7-9B3E28033832}" 8 | EndProject 9 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SegmentedControlSample.Droid", "Droid\SegmentedControlSample.Droid.csproj", "{3AC1889A-F03D-4678-BAD2-AAE0C945876A}" 10 | EndProject 11 | Global 12 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 13 | Debug|Any CPU = Debug|Any CPU 14 | Debug|iPhone = Debug|iPhone 15 | Debug|iPhoneSimulator = Debug|iPhoneSimulator 16 | Release|Any CPU = Release|Any CPU 17 | Release|iPhone = Release|iPhone 18 | Release|iPhoneSimulator = Release|iPhoneSimulator 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {4F5F7BA1-FEE0-44E0-870D-0377510AEB09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 22 | {4F5F7BA1-FEE0-44E0-870D-0377510AEB09}.Debug|Any CPU.Build.0 = Debug|Any CPU 23 | {4F5F7BA1-FEE0-44E0-870D-0377510AEB09}.Debug|iPhone.ActiveCfg = Debug|Any CPU 24 | {4F5F7BA1-FEE0-44E0-870D-0377510AEB09}.Debug|iPhone.Build.0 = Debug|Any CPU 25 | {4F5F7BA1-FEE0-44E0-870D-0377510AEB09}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU 26 | {4F5F7BA1-FEE0-44E0-870D-0377510AEB09}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU 27 | {4F5F7BA1-FEE0-44E0-870D-0377510AEB09}.Release|Any CPU.ActiveCfg = Release|Any CPU 28 | {4F5F7BA1-FEE0-44E0-870D-0377510AEB09}.Release|Any CPU.Build.0 = Release|Any CPU 29 | {4F5F7BA1-FEE0-44E0-870D-0377510AEB09}.Release|iPhone.ActiveCfg = Release|Any CPU 30 | {4F5F7BA1-FEE0-44E0-870D-0377510AEB09}.Release|iPhone.Build.0 = Release|Any CPU 31 | {4F5F7BA1-FEE0-44E0-870D-0377510AEB09}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU 32 | {4F5F7BA1-FEE0-44E0-870D-0377510AEB09}.Release|iPhoneSimulator.Build.0 = Release|Any CPU 33 | {D76C5B18-720E-4D94-AAD7-9B3E28033832}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator 34 | {D76C5B18-720E-4D94-AAD7-9B3E28033832}.Debug|Any CPU.Build.0 = Debug|iPhoneSimulator 35 | {D76C5B18-720E-4D94-AAD7-9B3E28033832}.Debug|iPhone.ActiveCfg = Debug|iPhone 36 | {D76C5B18-720E-4D94-AAD7-9B3E28033832}.Debug|iPhone.Build.0 = Debug|iPhone 37 | {D76C5B18-720E-4D94-AAD7-9B3E28033832}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator 38 | {D76C5B18-720E-4D94-AAD7-9B3E28033832}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator 39 | {D76C5B18-720E-4D94-AAD7-9B3E28033832}.Release|Any CPU.ActiveCfg = Release|iPhone 40 | {D76C5B18-720E-4D94-AAD7-9B3E28033832}.Release|Any CPU.Build.0 = Release|iPhone 41 | {D76C5B18-720E-4D94-AAD7-9B3E28033832}.Release|iPhone.ActiveCfg = Release|iPhone 42 | {D76C5B18-720E-4D94-AAD7-9B3E28033832}.Release|iPhone.Build.0 = Release|iPhone 43 | {D76C5B18-720E-4D94-AAD7-9B3E28033832}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator 44 | {D76C5B18-720E-4D94-AAD7-9B3E28033832}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator 45 | {3AC1889A-F03D-4678-BAD2-AAE0C945876A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 46 | {3AC1889A-F03D-4678-BAD2-AAE0C945876A}.Debug|Any CPU.Build.0 = Debug|Any CPU 47 | {3AC1889A-F03D-4678-BAD2-AAE0C945876A}.Debug|Any CPU.Deploy.0 = Debug|Any CPU 48 | {3AC1889A-F03D-4678-BAD2-AAE0C945876A}.Debug|iPhone.ActiveCfg = Debug|Any CPU 49 | {3AC1889A-F03D-4678-BAD2-AAE0C945876A}.Debug|iPhone.Build.0 = Debug|Any CPU 50 | {3AC1889A-F03D-4678-BAD2-AAE0C945876A}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU 51 | {3AC1889A-F03D-4678-BAD2-AAE0C945876A}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU 52 | {3AC1889A-F03D-4678-BAD2-AAE0C945876A}.Release|Any CPU.ActiveCfg = Release|Any CPU 53 | {3AC1889A-F03D-4678-BAD2-AAE0C945876A}.Release|Any CPU.Build.0 = Release|Any CPU 54 | {3AC1889A-F03D-4678-BAD2-AAE0C945876A}.Release|iPhone.ActiveCfg = Release|Any CPU 55 | {3AC1889A-F03D-4678-BAD2-AAE0C945876A}.Release|iPhone.Build.0 = Release|Any CPU 56 | {3AC1889A-F03D-4678-BAD2-AAE0C945876A}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU 57 | {3AC1889A-F03D-4678-BAD2-AAE0C945876A}.Release|iPhoneSimulator.Build.0 = Release|Any CPU 58 | EndGlobalSection 59 | GlobalSection(SolutionProperties) = preSolution 60 | HideSolutionNode = FALSE 61 | EndGlobalSection 62 | GlobalSection(ExtensibilityGlobals) = postSolution 63 | SolutionGuid = {9DF78613-5FDE-4029-9F39-C152B8780362} 64 | EndGlobalSection 65 | EndGlobal 66 | -------------------------------------------------------------------------------- /iOS/SegmentedControlSample.iOS.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | iPhoneSimulator 6 | {D76C5B18-720E-4D94-AAD7-9B3E28033832} 7 | {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 8 | Exe 9 | SegmentedControlSample.iOS 10 | SegmentedControlSample.iOS 11 | Resources 12 | 13 | 14 | true 15 | full 16 | false 17 | bin\iPhoneSimulator\Debug 18 | DEBUG;ENABLE_TEST_CLOUD; 19 | prompt 20 | 4 21 | iPhone Developer 22 | true 23 | true 24 | true 25 | 20393 26 | SdkOnly 27 | x86_64 28 | HttpClientHandler 29 | x86 30 | 31 | 32 | pdbonly 33 | true 34 | bin\iPhone\Release 35 | prompt 36 | 4 37 | iPhone Developer 38 | true 39 | Entitlements.plist 40 | SdkOnly 41 | ARM64 42 | HttpClientHandler 43 | x86 44 | 45 | 46 | pdbonly 47 | true 48 | bin\iPhoneSimulator\Release 49 | prompt 50 | 4 51 | iPhone Developer 52 | true 53 | None 54 | x86_64 55 | HttpClientHandler 56 | x86 57 | 58 | 59 | true 60 | full 61 | false 62 | bin\iPhone\Debug 63 | DEBUG;ENABLE_TEST_CLOUD; 64 | prompt 65 | 4 66 | iPhone Developer 67 | true 68 | true 69 | true 70 | true 71 | true 72 | Entitlements.plist 73 | 58126 74 | SdkOnly 75 | ARM64 76 | HttpClientHandler 77 | x86 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | ..\packages\Xamarin.Forms.2.3.4.247\lib\Xamarin.iOS10\Xamarin.Forms.Core.dll 86 | 87 | 88 | ..\packages\Xamarin.Forms.2.3.4.247\lib\Xamarin.iOS10\Xamarin.Forms.Platform.dll 89 | 90 | 91 | ..\packages\Xamarin.Forms.2.3.4.247\lib\Xamarin.iOS10\Xamarin.Forms.Platform.iOS.dll 92 | 93 | 94 | ..\packages\Xamarin.Forms.2.3.4.247\lib\Xamarin.iOS10\Xamarin.Forms.Xaml.dll 95 | 96 | 97 | 98 | 99 | {4F5F7BA1-FEE0-44E0-870D-0377510AEB09} 100 | SegmentedControlSample 101 | 102 | 103 | 104 | 105 | false 106 | 107 | 108 | false 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /Droid/SegmentedControlSample.Droid.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | {3AC1889A-F03D-4678-BAD2-AAE0C945876A} 7 | {EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 8 | Library 9 | SegmentedControlSample.Droid 10 | SegmentedControlSample.Droid 11 | v8.0 12 | True 13 | Resources\Resource.designer.cs 14 | Resource 15 | Properties\AndroidManifest.xml 16 | Resources 17 | Assets 18 | true 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\Debug 25 | DEBUG; 26 | prompt 27 | 4 28 | None 29 | 30 | 31 | true 32 | pdbonly 33 | true 34 | bin\Release 35 | prompt 36 | 4 37 | true 38 | false 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | ..\packages\Xamarin.Android.Support.v4.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.v4.dll 47 | 48 | 49 | ..\packages\Xamarin.Android.Support.Vector.Drawable.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.Vector.Drawable.dll 50 | 51 | 52 | ..\packages\Xamarin.Android.Support.Animated.Vector.Drawable.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.Animated.Vector.Drawable.dll 53 | 54 | 55 | ..\packages\Xamarin.Android.Support.v7.AppCompat.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.v7.AppCompat.dll 56 | 57 | 58 | ..\packages\Xamarin.Android.Support.v7.RecyclerView.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.v7.RecyclerView.dll 59 | 60 | 61 | ..\packages\Xamarin.Android.Support.Design.23.3.0\lib\MonoAndroid43\Xamarin.Android.Support.Design.dll 62 | 63 | 64 | ..\packages\Xamarin.Android.Support.v7.CardView.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.v7.CardView.dll 65 | 66 | 67 | ..\packages\Xamarin.Android.Support.v7.MediaRouter.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.v7.MediaRouter.dll 68 | 69 | 70 | ..\packages\Xamarin.Forms.2.3.4.247\lib\MonoAndroid10\FormsViewGroup.dll 71 | 72 | 73 | ..\packages\Xamarin.Forms.2.3.4.247\lib\MonoAndroid10\Xamarin.Forms.Core.dll 74 | 75 | 76 | ..\packages\Xamarin.Forms.2.3.4.247\lib\MonoAndroid10\Xamarin.Forms.Platform.Android.dll 77 | 78 | 79 | ..\packages\Xamarin.Forms.2.3.4.247\lib\MonoAndroid10\Xamarin.Forms.Platform.dll 80 | 81 | 82 | ..\packages\Xamarin.Forms.2.3.4.247\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll 83 | 84 | 85 | 86 | 87 | {4F5F7BA1-FEE0-44E0-870D-0377510AEB09} 88 | SegmentedControlSample 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /SegmentedControlSample/Controls/SegmentedBarControl.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using SegmentedControlSample.Controls; 5 | using Xamarin.Forms; 6 | 7 | namespace SegmentedControlSample 8 | { 9 | public class SegmentedBarControl: ContentView 10 | { 11 | public static readonly BindableProperty ItemSelectedProperty = BindableProperty.Create(nameof(ItemSelected), typeof(string), typeof(SegmentedBarControl), null); 12 | public static readonly BindableProperty ChildrenProperty = BindableProperty.Create(nameof(Children), typeof(List), typeof(SegmentedBarControl), null); 13 | public static readonly BindableProperty TextColorProperty = BindableProperty.Create(nameof(TextColor), typeof(Color), typeof(SegmentedBarControl), Color.DarkGray); 14 | public static readonly BindableProperty SelectedLineColorProperty = BindableProperty.Create(nameof(SelectedLineColor), typeof(Color), typeof(SegmentedBarControl), Color.Black); 15 | public static readonly BindableProperty SelectedTextColorProperty = BindableProperty.Create(nameof(SelectedTextColor), typeof(Color), typeof(SegmentedBarControl), Color.Black); 16 | public static readonly BindableProperty AutoScrollProperty = BindableProperty.Create(nameof(AutoScroll), typeof(bool), typeof(SegmentedBarControl), true); 17 | 18 | 19 | public static readonly BindableProperty SelectedItemChangedCommandProperty = BindableProperty.Create(nameof(SelectedItemChangedCommand), typeof(Command), typeof(SegmentedBarControl), default(Command), BindingMode.TwoWay, null, SelectedItemChangedCommandPropertyChanged); 20 | 21 | static void SelectedItemChangedCommandPropertyChanged(BindableObject bindable, object oldValue, object newValue) 22 | { 23 | var source = bindable as SegmentedBarControl; 24 | if (source == null) 25 | { 26 | return; 27 | } 28 | source.SelectedItemChangedCommandChanged(); 29 | } 30 | 31 | private void SelectedItemChangedCommandChanged() 32 | { 33 | OnPropertyChanged("SelectedItemChangedCommand"); 34 | } 35 | 36 | public Command SelectedItemChangedCommand 37 | { 38 | get 39 | { 40 | return (Command)GetValue(SelectedItemChangedCommandProperty); 41 | } 42 | set 43 | { 44 | SetValue(SelectedItemChangedCommandProperty, value); 45 | } 46 | } 47 | public delegate void SelectedItemChangedEventHandler(object sender, SelectedItemChangedEventArgs e); 48 | public event SelectedItemChangedEventHandler SelectedItemChanged; 49 | 50 | public string ItemSelected 51 | { 52 | get 53 | { 54 | return (string)GetValue(ItemSelectedProperty); 55 | } 56 | set 57 | { 58 | SetValue(ItemSelectedProperty, value); 59 | SelectedItemChanged(this, new SelectedItemChangedEventArgs(value)); 60 | SelectedItemChangedCommand?.Execute(value); 61 | } 62 | } 63 | 64 | public List Children 65 | { 66 | get 67 | { 68 | return (List)GetValue(ChildrenProperty); 69 | } 70 | set 71 | { 72 | SetValue(ChildrenProperty, value); 73 | } 74 | } 75 | 76 | public Color TextColor 77 | { 78 | get 79 | { 80 | return (Color)GetValue(TextColorProperty); 81 | } 82 | set 83 | { 84 | SetValue(TextColorProperty, value); 85 | } 86 | } 87 | 88 | public Color SelectedTextColor 89 | { 90 | get 91 | { 92 | return (Color)GetValue(SelectedTextColorProperty); 93 | } 94 | set 95 | { 96 | SetValue(SelectedTextColorProperty, value); 97 | } 98 | } 99 | 100 | public Color SelectedLineColor 101 | { 102 | get 103 | { 104 | return (Color)GetValue(SelectedLineColorProperty); 105 | } 106 | set 107 | { 108 | SetValue(SelectedLineColorProperty, value); 109 | } 110 | } 111 | 112 | public bool AutoScroll 113 | { 114 | get 115 | { 116 | return (bool)GetValue(AutoScrollProperty); 117 | } 118 | set 119 | { 120 | SetValue(AutoScrollProperty, value); 121 | } 122 | } 123 | 124 | 125 | StackLayout _mainContentLayout = new StackLayout(){ Spacing = 10, Orientation = StackOrientation.Horizontal }; 126 | StackLayout _lastElementSelected; 127 | ScrollViewWithNotBar _mainLayout = new ScrollViewWithNotBar() {VerticalOptions = LayoutOptions.Start, Orientation = ScrollOrientation.Horizontal }; 128 | 129 | void LoadChildrens(){ 130 | 131 | _mainContentLayout.Children.Clear(); 132 | foreach (var item in Children) 133 | { 134 | var label = new Label() 135 | { 136 | FontAttributes= FontAttributes.Bold, 137 | Text = item, 138 | TextColor=TextColor, 139 | Margin= new Thickness(10,0), 140 | HorizontalOptions = LayoutOptions.CenterAndExpand 141 | }; 142 | 143 | var boxview = new BoxView() { BackgroundColor = Color.Transparent, HeightRequest = 2, HorizontalOptions = LayoutOptions.FillAndExpand }; 144 | var childrenLayout = new StackLayout(){Spacing=5}; 145 | 146 | childrenLayout.Children.Add(label); 147 | childrenLayout.Children.Add(boxview); 148 | childrenLayout.ClassId = item; 149 | _mainContentLayout.Children.Add(childrenLayout); 150 | var tapGestureRecognizer = new TapGestureRecognizer(); 151 | tapGestureRecognizer.Tapped += (s, e) => { 152 | ItemSelected = ((StackLayout)s).ClassId; 153 | }; 154 | childrenLayout.GestureRecognizers.Add(tapGestureRecognizer); 155 | } 156 | 157 | 158 | _mainLayout.Content = _mainContentLayout; 159 | 160 | var mainContentLayout = new StackLayout() { Spacing = 0 }; 161 | mainContentLayout.Children.Add(_mainLayout); 162 | mainContentLayout.Children.Add(new BoxView() { HeightRequest = 0.5, HorizontalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.Silver }); 163 | 164 | this.Content = mainContentLayout; 165 | 166 | } 167 | 168 | void SelectElement(StackLayout itemSelected){ 169 | if (_lastElementSelected != null){ 170 | (_lastElementSelected.Children.First(p => p is BoxView) as BoxView).BackgroundColor = Color.Transparent; 171 | (_lastElementSelected.Children.First(p => p is Label) as Label).TextColor = TextColor; 172 | } 173 | 174 | (itemSelected.Children.First(p => p is BoxView) as BoxView).BackgroundColor = SelectedLineColor; 175 | (itemSelected.Children.First(p => p is Label) as Label).TextColor = SelectedTextColor; 176 | _lastElementSelected = itemSelected; 177 | 178 | if(AutoScroll) 179 | _mainLayout.ScrollToAsync(itemSelected, ScrollToPosition.MakeVisible, true); 180 | } 181 | 182 | protected override void OnPropertyChanged(string propertyName = null) 183 | { 184 | base.OnPropertyChanged(propertyName); 185 | 186 | if(propertyName == ItemSelectedProperty.PropertyName && Children != null && Children.Count > 0){ 187 | SelectElement(_mainContentLayout.Children[Children.IndexOf(ItemSelected)] as StackLayout); 188 | } else if (propertyName == ChildrenProperty.PropertyName && Children != null) 189 | { 190 | LoadChildrens(); 191 | if(string.IsNullOrEmpty(ItemSelected)){ 192 | ItemSelected = Children.First(); 193 | }else{ 194 | SelectElement(_mainContentLayout.Children[Children.IndexOf(ItemSelected)] as StackLayout); 195 | } 196 | } 197 | } 198 | } 199 | } 200 | --------------------------------------------------------------------------------