List view item with label and programmed control

R3muSGFXR3muSGFX USMember ✭✭
edited October 25 in Xamarin.Forms

Hello everybody.

I have developed a barcode app and I have reached the step of creating a settings page. Here I want to create an item on listview (or a row) with the following contents:

  • a label with the setting name
  • a label with the description of the setting name
  • a control (a picker or a switch) depending on the setting that I might use

So far I added the labels from my setting model class and it's showing them as it should, but my problem here is how can I define the picker or the switch from code. I tried to add the picker and switch from the XAML part and they show up as it should from the properties of the setting model, but I can not access the switch/picker so that I can use their settings or add items to the picker.

My XAML code looks like this:

`

            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Grid Padding="3">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Label Grid.Row="0" Grid.Column="0" Text="{Binding SettingName}" FontAttributes="Bold"/>
                            <Label Grid.Row="1" Grid.Column="0" Text="{Binding SettingDescription}" FontSize="Micro"/>
                            <Picker Grid.RowSpan="2" Grid.Column="1" IsVisible="{Binding IsPicker}" x:Name="pickerList"/>
                            <Switch Grid.RowSpan="2" Grid.Column="1" IsVisible="{Binding IsSwitch}" x:Name="switchList"/>
                        </Grid>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>`

And the view after deploy looks like this:

Is this the right approach to achieve my goal or what is it that I should correct ?
Thanks in advance.

Answers

  • DK90DK90 USMember ✭✭✭

    but I can not access the switch/picker so that I can use their settings or add items to the picker.

    What does this mean? You want to access the picker/switch in the code behind to populate the items. If that's the case Picker has the ItemsSource property which you can bind it with the underlying business model.

  • R3muSGFXR3muSGFX USMember ✭✭

    @DK90 said:

    but I can not access the switch/picker so that I can use their settings or add items to the picker.

    What does this mean? You want to access the picker/switch in the code behind to populate the items. If that's the case Picker has the ItemsSource property which you can bind it with the underlying business model.

    That's right. But when I try to access it does not appear in my code. I'm not sure how can I bind that picker or switch to my model, that's why I'm stuck right now...

Sign In or Register to comment.