public void ClickingSelectedSegmentShouldNotTriggerSelectionChanged() { var selectedIndexesChangedCount = 0; var itemClickCount = 0; var clickCount = 0; SegmentedItem itemClicked = null; SegmentedItem itemItemClicked = null; SegmentedItem itemExpected = null; Form(form => { itemExpected = new ButtonSegmentedItem { Text = "Click Me!", Selected = true }; var segmentedButton = new SegmentedButton { SelectionMode = SegmentedSelectionMode.Single, Items = { "First", itemExpected, "Last" } }; segmentedButton.SelectedIndexesChanged += (sender, e) => selectedIndexesChangedCount++; segmentedButton.ItemClick += (sender, e) => { itemItemClicked = e.Item; itemClickCount++; }; itemExpected.Click += (sender, e) => { itemClicked = sender as SegmentedItem; clickCount++; Application.Instance.AsyncInvoke(form.Close); }; Assert.IsTrue(itemExpected.Selected, "#1.1"); form.Content = new StackLayout { Spacing = 10, Padding = 10, Items = { "Click the selected segment", segmentedButton } }; }, -1); Assert.AreEqual(0, selectedIndexesChangedCount, "#2.1"); Assert.AreEqual(1, itemClickCount, "#2.2"); Assert.AreEqual(1, clickCount, "#2.3"); Assert.IsNotNull(itemExpected, "#3.1"); Assert.AreSame(itemExpected, itemClicked, "#3.2"); Assert.AreSame(itemExpected, itemItemClicked, "#3.3"); }
/// <summary> /// Raises the SelectedChanged event. /// </summary> public void OnSelectedChanged(SegmentedItem widget, EventArgs e) { using (widget.Platform.Context) widget.OnSelectedChanged(e); }
string ItemDesc(SegmentedItem item) => item != null ? $"{item.GetType().Name}, {item.Text}" : "(null)";
/// <summary> /// Raises the Click event. /// </summary> public void OnClick(SegmentedItem widget, EventArgs e) { using (widget.Platform.Context) widget.OnClick(e); }
void LogEvents(SegmentedItem item) { item.Click += (sender, e) => Log.Write(sender, $"Click: {ItemDesc(item)}"); }