Xamarin Forms Switch XAML -


i'm new in xamarin , i'm trying create simple page components.

one of these component switch works fine change basic text "inactive/active" "male/female"

i've seen in xaml windows phone there toggleswitch component on/offcontent property can't seems find equivalent in xaml xamarin forms

any idea ?

thank you!

the lack of built in switch options or @ least lack of being able rename swtich options has been asked few times. go custom renders, modify text @ os level or chose build own switch. switch 2 buttons laid out horizontally text yes , no. selected button gets red border, un selected transparent.

class customswitch : grid {      public event eventhandler<selecteditemchangedeventargs> itemselected;     private button negative;     private button positive;      public static readonly bindableproperty selecteditemproperty = bindableproperty.create<customswitch, object>(t => t.selecteditem, null, bindingmode.twoway, propertychanged: onselecteditemchanged);      public customswitch()     {          try         {             this.horizontaloptions = layoutoptions.center;             this.verticaloptions = layoutoptions.center;              negative = new button();             negative.text = "no";             negative.style = <yournamespace>.appstyling.style_button_switch;             negative.clicked += (o,s) => onselecteditemchanged(this, itemselected, (int)classes.collections.enums.selectionstatus.false);              positive = new button();             positive.text = "yes";             positive.style = <yournamespace>.appstyling.style_button_switch;             positive.clicked += (o, s) => onselecteditemchanged(this, itemselected, (int)classes.collections.enums.selectionstatus.true);                             this.children.add(negative, 0,0);             this.children.add(positive, 1,0);         }         catch(system.exception ex)         {             <yournamespace>.classes.helpers.helper_errorhandling.senderrortoserver(ex, this.gettype().name, system.reflection.methodbase.getcurrentmethod().name);         }      }      public object selecteditem     {                 {             return base.getvalue(selecteditemproperty);         }         set         {             if (selecteditem != value)             {                 base.setvalue(selecteditemproperty, value);                 internalupdateselected();             }         }     }      private void internalupdateselected()     {         if((int)selecteditem == (int)classes.collections.enums.selectionstatus.false)         {             negative.bordercolor = <yournamespace>.appstyling.color_selected;             positive.bordercolor = <yournamespace>.appstyling.color_unselected;             positive.opacity = <yournamespace>.appstyling.opaque_high;         }         else if ((int)selecteditem == (int)classes.collections.enums.selectionstatus.true)         {             negative.bordercolor = <yournamespace>.appstyling.color_unselected;             negative.opacity = <yournamespace>.appstyling.opaque_high;             positive.bordercolor = <yournamespace>.appstyling.color_selected;         }         else         {             negative.bordercolor = <yournamespace>.appstyling.color_unselected;             negative.opacity = <yournamespace>.appstyling.opaque_high;             positive.bordercolor = <yournamespace>.appstyling.color_unselected;             positive.opacity = <yournamespace>.appstyling.opaque_high;         }     }      private static void onselecteditemchanged(bindableobject bindable, object oldvalue, object newvalue)     {         customswitch boundswitch = (customswitch)bindable;          if((int)newvalue != (int)classes.collections.enums.selectionstatus.unselected)         {             boundswitch.selecteditem = (int)newvalue == (int)classes.collections.enums.selectionstatus.false ? (int)classes.collections.enums.selectionstatus.false : (int)classes.collections.enums.selectionstatus.true;         }           if (boundswitch.itemselected != null)         {             boundswitch.itemselected(boundswitch, new selecteditemchangedeventargs(newvalue));         }         boundswitch.internalupdateselected();     }  } 

Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -