0

I am using radio button with listview and on listview item click I want to make radio button checked/selected but unfortunately not able to select the radio button.

                       <StackLayout  VerticalOptions="CenterAndExpand" HeightRequest="200" HorizontalOptions="CenterAndExpand" >
                        <ListView RowHeight="45" IsVisible="true" ItemsSource="{Binding Items}" BackgroundColor="#5679d1"
                                  SelectedItem="{Binding objItemSelected, Mode=TwoWay}" 
                                  HasUnevenRows="true" SeparatorVisibility="Default" SeparatorColor="White">
                            <ListView.ItemTemplate>  
                                <DataTemplate>  
                                    <ViewCell>

                                            <Grid>
                                                <Label Text="{Binding Questions}" TextColor="Black" Grid.Column="0" 
                                                       Grid.Row="0" Grid.ColumnSpan="2" HorizontalOptions="Center">
                                                </Label> 
                                                 <controls:CustomRadioButton HeightRequest="15" HorizontalOptions="End" Checked="{Binding Radiobtn}" IsVisible="true"  Grid.Row="0" Grid.Column="3"/>
                                            </Grid>
                                    </ViewCell>
                                </DataTemplate>  
                            </ListView.ItemTemplate>  
                        </ListView>
                </StackLayout>
Sandeep Singh
  • 81
  • 1
  • 11
  • I've voted to close, since in my opinion this question is not understandable at all. Could you edit the question to clarify what you are trying to achieve? – Paul Kertscher Jan 11 '19 at 06:31

2 Answers2

0

According to your description, I guess that you want to have two event, one is ListView Itemselected, another is RadioButton check event in Listview. I do one sample about this, but I add Button in listview, replace RadioButton, you can take a look:

 <StackLayout>
    <ListView ItemsSource="{Binding models}" RowHeight="40" ItemSelected="ListView_ItemSelected">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <StackLayout HorizontalOptions="StartAndExpand" Orientation="Horizontal">

                            <Label
                                x:Name="label1"
                                Text="{Binding Name}"
                                TextColor="Black" />
                            <Button x:Name="btn1" Text="{Binding Description}" Clicked="OnButtonClick" />


                    </StackLayout>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</StackLayout>

  private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
    {
        testmodel model = (testmodel)e.SelectedItem;
        //Console.WriteLine(model.Name);
        DisplayAlert("Alert", model.Name, "OK");
    }

    private void OnButtonClick(object sender, EventArgs e)
    {
        Button btn = (Button)sender;
        StackLayout listviewiten = (StackLayout)btn.Parent;
        Label label = (Label)listviewiten.Children[0];
        DisplayAlert("Alert", label.Text, "OK");
        //Console.WriteLine(label.Text);


    }
Cherry Bu - MSFT
  • 10,160
  • 1
  • 10
  • 16
0

You haven't posted the code for objItemSelected, so you may need to mix it with my answer, but to achieve what you want you should have this:

public object objItemSelected
{
  get => null;
  set
  {
     if (value == null)
        return;
     value.Radiobtn = true;
     onPropertyChanged(nameof(objItemSelected));
  }
}
Ivan Ičin
  • 9,672
  • 5
  • 36
  • 57