3
votes

enter image description hereI am working on a listview in which I have a label and Picker.I want to detect the selected item of the picker which is inside the list view.I am not able to access the x:Name of picker in Xaml.cs file.Below is my code.Any one please help me if i am going in a wrong direction.Thanks in Advance.

Here is my Xaml code:

                    <ListView x:Name="MasterRoomList" BackgroundColor="Transparent"
                                      ItemsSource="{Binding MasterRoomWindowsList}"
                                      IsVisible="{Binding RoomsVisibility}" ItemTapped="OnItemTapped" SeparatorVisibility="None">
                  <ListView.HeightRequest>
                    <OnIdiom x:TypeArguments="x:Double">
                      <OnIdiom.Phone>
                        <OnPlatform x:TypeArguments="x:Double" iOS="150" Android="150" WinPhone="150" />
                      </OnIdiom.Phone>
                      <OnIdiom.Tablet>
                        <OnPlatform x:TypeArguments="x:Double" iOS="300" Android="300" WinPhone="300" />
                      </OnIdiom.Tablet>
                    </OnIdiom>
                  </ListView.HeightRequest>
                  <ListView.ItemTemplate>
                    <DataTemplate>
                      <ViewCell>
                        <Grid Padding="2">
                          <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                          </Grid.ColumnDefinitions>
                          <Label Grid.Column="0" Text="{Binding RoomName}" TextColor="Black" FontFamily="Avenir Book" VerticalTextAlignment="Center">
                            <Label.FontSize>
                              <OnIdiom x:TypeArguments="x:Double">
                                <OnIdiom.Phone>
                                  <OnPlatform x:TypeArguments="x:Double" iOS="13" Android="13" WinPhone="13" />
                                </OnIdiom.Phone>
                                <OnIdiom.Tablet>
                                  <OnPlatform x:TypeArguments="x:Double" iOS="20" Android="20" WinPhone="20" />
                                </OnIdiom.Tablet>
                              </OnIdiom>
                            </Label.FontSize>
                          </Label>
                          <Picker x:Name="CurtainPicker" BackgroundColor="Transparent" TextColor="Black" ItemsSource="{Binding CurtainsTypeList}"  SelectedIndexChanged="CurtainPicker_OnSelectedIndexChanged" Title="Select Style" Grid.Column="1" HorizontalOptions="FillAndExpand" VerticalOptions="CenterAndExpand">
                            <Picker.HeightRequest>
                              <OnIdiom x:TypeArguments="x:Double">
                                <OnIdiom.Tablet>
                                  <OnPlatform x:TypeArguments="x:Double" iOS="40" Android="40"/>
                                </OnIdiom.Tablet>
                                <OnIdiom.Phone>
                                  <OnPlatform x:TypeArguments="x:Double" iOS="30" Android="30"/>
                                </OnIdiom.Phone>
                              </OnIdiom>
                            </Picker.HeightRequest>
                          </Picker>
                        </Grid>
                      </ViewCell>
                    </DataTemplate>
                  </ListView.ItemTemplate>
                </ListView>

Here is my Xaml.cs Code:

private void CurtainPicker_OnSelectedIndexChanged(object sender, EventArgs e)
    {
        var selectedItem = (string) CurtainPicker.SelectedItem;


    }
1

1 Answers

1
votes
var picker = (Picker)sender;
var selectedItem = (string) picker.SelectedItem;