Created
June 6, 2014 04:46
-
-
Save detroitpro/f94fd07ee4a907d1575c to your computer and use it in GitHub Desktop.
Segmented Render for Xamarin.Forms.
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 SegmentedControlRenderer : NativeRenderer | |
| { | |
| protected override void OnModelSet(VisualElement model) | |
| { | |
| base.OnModelSet (model); | |
| SegmentedControlView segmentedControlView = (SegmentedControlView)this.Model; | |
| var native = new UISegmentedControl (); | |
| native.Frame = new RectangleF (20, 20, 280, 40); | |
| // Create the view using the properties from the model. | |
| native.InsertSegment ("One", 0, false); | |
| native.InsertSegment ("Two", 1, false); | |
| native.SelectedSegment = segmentedControlView.SelectedItem; | |
| native.ValueChanged += (s, e) => { | |
| var ctrl = s as UISegmentedControl; | |
| segmentedControlView.SelectedItem = ctrl.SelectedSegment; | |
| }; | |
| // Add it as a child to this view by setting it as the control | |
| // for this renderer. | |
| SetNativeControl (native); | |
| } | |
| } |
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 SegmentedControlView : BoxView | |
| { | |
| public SegmentedControlView() | |
| { | |
| } | |
| public static readonly BindableProperty SelectedItemProperty = | |
| BindableProperty.Create<SegmentedControlView,int> ( | |
| p => p.SelectedItem, default(int)); | |
| public int SelectedItem { | |
| get { return (int)GetValue (SelectedItemProperty); } | |
| set { | |
| Debug.WriteLine ("New Value:" + value); | |
| SetValue (SelectedItemProperty, value); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm getting lot of errors while this code in my project will you please tell the libraries to be used