SegmentedControl icon indicating copy to clipboard operation
SegmentedControl copied to clipboard

SegmentedControlOption is not bindable

Open dodikk opened this issue 7 years ago • 1 comments

        <segmented_control:SegmentedControl x:Name="SegControl" 
                                            HeightRequest="39"
                                            Margin="20, 0"
                                            TintColor="#007AFF" 
                                            SelectedSegment="0"
                                            ValueChanged="PieChart__SelectedTabChanged">
            <segmented_control:SegmentedControl.Children>
                <segmented_control:SegmentedControlOption Text="{Binding MonthSegmentName}" />
                <segmented_control:SegmentedControlOption Text="{Binding YearSegmentName}" />
            </segmented_control:SegmentedControl.Children>
        </segmented_control:SegmentedControl>
        <StackLayout x:Name="SegContent" HeightRequest="228">
            <Label Text="{Binding MockPieChartContentText}" />
        </StackLayout>

The xaml example from the readme works if tab names are string constants. It does not when I try to use bindings (I see empty segments). Reproduced on iOS platform.

// page class

namespace PracticeDashboard.Views
{
    using PracticeDashboard.ViewModels;
    using Xamarin.Forms;

    public partial class PipelineDetailPage : ContentPage
    {
        public PipelineDetailPage()
        {
            InitializeComponent();
        }

        private PipelineDetailPageViewModel viewModel => (PipelineDetailPageViewModel)this.BindingContext;

        public void PieChart__SelectedTabChanged(
            object sender, 
            SegmentedControl.FormsPlugin.Abstractions.ValueChangedEventArgs e)
        {
            var indexOfNewTab = e.NewValue;

            var viewModel = this.viewModel;
            viewModel.OnSelectedPieChartTabWithIndex(indexOfNewTab);
        }
    }
}

// ViewModel

        #region PieChart
        public void OnSelectedPieChartTabWithIndex(int selectedTabIndex)
        {
            switch (selectedTabIndex)
            {
                case 0:
                    this.MockPieChartContentText = this.MonthSegmentName;
                    break;

                case 1:
                    this.MockPieChartContentText = this.YearSegmentName;
                    break;

                default:
                    // invalid input
                    // IDLE
                    // 
                    // TODO: maybe throw exception
                    //
                    break;
            }
        }

        public string MonthSegmentName { get; set; } = "November 2017";
        public string YearSegmentName { get; set; } = "YTD 2018";


        public string MockPieChartContentText { get; set; } = "November 2017";

        #endregion

dodikk avatar Feb 05 '18 11:02 dodikk

same problem, in fact if you set any new text in code after the control is drawn, the control does not refresh

CarLoOSX avatar Mar 28 '18 11:03 CarLoOSX