// Not working - Unable to bind VisualStateGroup // Still trying to implement this with only code public class SegmentCode : Border { readonly string[] items = { "Pending", "Confirmed", "Completed" }; // Extending is not equivalent to X:Name, looking for a solution class SegmentButton : Button { public SegmentButton() => this.Margins(0, 0, 8, 0); } public SegmentCode() { Padding = 3; Margin = 8; StrokeShape = new RoundRectangle { CornerRadius = new CornerRadius(10) }; SetDynamicResource(BackgroundColorProperty, "Tertiary"); var layout = new HorizontalStackLayout() .ItemsSource(items) .ItemTemplate(new DataTemplate(() => new RadioButton { ControlTemplate = new ControlTemplate(() => new SegmentButton() .Bind(Button.TextProperty, "Content", source: RelativeBindingSource.TemplatedParent)) }.Bind(RadioButton.ContentProperty))); RadioButtonGroup.SetGroupName(layout, "SegmentRadios"); // Todo: Add VisualStateGroup to the baindable layout // Todo: Properly name child crontrols to reference in VistualState var vsGroups = new VisualStateGroup() { Name = "CheckedStates", }; vsGroups.States.Add(new VisualState { Name = "Checked", Setters = { new Setter { TargetName = nameof(SegmentButton), Property = Button.BackgroundColorProperty, Value = Colors.Indigo } } }); vsGroups.States.Add(new VisualState { Name = "Unchecked", Setters = { new Setter { TargetName = nameof(SegmentButton), Property = Button.BackgroundColorProperty, Value = Colors.Transparent }, new Setter { TargetName = nameof(SegmentButton), Property = Button.TextColorProperty, Value = Colors.Indigo } } }); var vsList = new VisualStateGroupList(); vsList.Add(vsGroups) VisualStateManager.SetVisualStateGroups(layout, vsGroups); Content = layout; } }