azchohfi / AndroidSegmentedControl.Droid

https://github.com/Kaopiz/android-segmented-control binding project for Xamarin.Android
Apache License 2.0
2 stars 1 forks source link

Unable to Bind Text in Children #1

Closed CarLoOSX closed 6 years ago

CarLoOSX commented 6 years ago

Hello! I cannot Bind the text after segmented control is drawn.

Heres my code:


public string HorizontalText
        {
            get => _horizontalText;
            set
            {
                _horizontalText = value;
                RaisePropertyChanged(() => HorizontalText);
            }
        }

        public string VerticalText
        {
            get => _verticalText;
            set
            {
                _verticalText = value;
                RaisePropertyChanged(() => VerticalText);
                //No va el bindeo usamos message center y listo
                MessagingCenter.Send(this, "ChangeSegmentedText");
            }
        }

I've tried to use also message center but nothing happens:

public SettingsPage()
        {
            InitializeComponent();
            this.SizeChanged += OrientationChanged;

            MessagingCenter.Subscribe<SettingsViewModel>(this, "ChangeSegmentedText", (sender) =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    SegmentedControl = new Plugin.Segmented.Control.SegmentedControl();
                    SegmentedControl.Children.Add(new Plugin.Segmented.Control.SegmentedControlOption()
                    {
                        Text = sender.VerticalText
                    });
                    SegmentedControl.Children.Add(new Plugin.Segmented.Control.SegmentedControlOption()
                    {
                        Text = sender.HorizontalText
                    });
                    ForceLayout();
                    /*SegmentedControl.Children[0].Text = sender.VerticalText;
                    SegmentedControl.Children[1].Text = sender.HorizontalText;*/
                });
            });

        }

heres my layout:

<ContentPage
    BackgroundColor="#e2e2e2"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:forms="clr-namespace:Lottie.Forms;assembly=Lottie.Forms"
    xmlns:control="clr-namespace:Plugin.Segmented.Control;assembly=Plugin.Segmented"
    x:Class="xxx.Views.SettingsPage"
    xmlns:viewModelBase="clr-namespace:xxx.ViewModels.Base;assembly=xxx"
    viewModelBase:ViewModelLocator.AutoWireViewModel="true"
    x:Name="content">
    <ContentPage.Content>
        <ScrollView>
            <RelativeLayout
                x:Name="mainLayout">
                <StackLayout
                    x:Name="gridView">
                    <Grid
                        Padding="0,75,0,75"
                        RowSpacing="15">
                        <Grid.RowDefinitions>
                            <RowDefinition
                                Height="Auto" />
                            <RowDefinition
                                Height="Auto" />
                            <RowDefinition
                                Height="Auto" />
                            <RowDefinition
                                Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid
                            Grid.Row="0">
                            <Grid.RowDefinitions>
                                <RowDefinition
                                    Height="Auto" />
                                <RowDefinition
                                    Height="Auto" />
                                <RowDefinition
                                    Height="50" />
                            </Grid.RowDefinitions>
                            <Label
                                Grid.Row="0"
                                FontSize="Medium"
                                TextColor="#d8353d"
                                Text="{Binding OrientationText}" />
                            <BoxView
                                Grid.Row="1"
                                Color="#d8353d"
                                HorizontalOptions="FillAndExpand"
                                HeightRequest="1" />
                            <control:SegmentedControl
                                x:Name="SegmentedControl"
                                Grid.Row="2"
                                VerticalOptions="CenterAndExpand"
                                TintColor="#3d3d3d"
                                SelectedSegment="{Binding SelectedOrientationIndex, Mode=TwoWay}"
                                SelectedTextColor="White"
                                DisabledColor="Gray">
                                <control:SegmentedControl.Children>
                                    <control:SegmentedControlOption
                                        BindingContext="{Binding BindingContext, Source={x:Reference content}}"
                                        Text="{Binding VerticalText, Mode=TwoWay}" />
                                    <control:SegmentedControlOption
                                        BindingContext="{Binding BindingContext, Source={x:Reference content}}"
                                        Text="{Binding HorizontalText, Mode=TwoWay}" />
                                </control:SegmentedControl.Children>
                            </control:SegmentedControl>
                        </Grid>
...
azchohfi commented 6 years ago

This source code is not the bindings one. This repo is only the Android native bindings for Xamarin.Android, not for Xamarin.Forms. I think you are trying to report to this repo: https://github.com/1iveowl/Plugin.SegmentedControl or https://github.com/alexrainman/SegmentedControl