Xamarin
Xamarin

Reputation: 23

How to bind values to a picker inside listview in xamarin

In xamarin Forms i am using list View inside which i need to implement picker .Since we cannot take out id from listview i couldnot load value to picker. Is there any possible way to do this.Here is the xaml code containg listview

      <ListView x:Name="list_propertyCell" RowHeight="350" SeparatorVisibility="None">
    <ListView.ItemTemplate>
      <DataTemplate>
        <ViewCell>
          <StackLayout Orientation="Vertical">

            <Grid HorizontalOptions="FillAndExpand"
   Margin="10" >
              <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
              </Grid.RowDefinitions>

              <Grid.ColumnDefinitions>

                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
              </Grid.ColumnDefinitions>

              <Label Text="Claim Period-Month" TextColor="Gray"  FontSize="14" FontFamily="avenir" Grid.Row="0" Grid.Column="0" >
                <Label.FontFamily>
                  <OnPlatform x:TypeArguments="x:String"
                           iOS="avenir"
                                   Android="Fonts/AvenirLTStd-Book.ttf#AvenirLTStd-Book"/>
                </Label.FontFamily>
              </Label>
              <Entry Text="{Binding PropertyDate}" Placeholder="{Binding ddlvalue}" FontSize="14" Grid.Row="1" Grid.Column="0" IsEnabled="{Binding enabled}" PlaceholderColor="Black">
                <Entry.FontFamily>
                  <OnPlatform x:TypeArguments="x:String"
                         iOS="avenir"
                                   Android="Fonts/AvenirLTStd-Book.ttf#AvenirLTStd-Book"/>
                </Entry.FontFamily>
              </Entry>
                                <Button Grid.Row="1" Grid.Column="0" Clicked="populate" BackgroundColor="Transparent" IsEnabled="{Binding enabled}"/>
              <Label Text="Claim Period-Year" TextColor="Gray"  FontSize="14" FontFamily="avenir" Grid.Row="0" Grid.Column="1" >
                <Label.FontFamily>
                  <OnPlatform x:TypeArguments="x:String"
                           iOS="avenir"
                                   Android="Fonts/AvenirLTStd-Book.ttf#AvenirLTStd-Book"/>
                </Label.FontFamily>
              </Label>
                <Entry Text="{Binding PropertyDate1}" Completed="periodyear" ClassId="{Binding claimdetailId}" FontSize="14" Grid.Row="1" Grid.Column="1" IsEnabled="{Binding enabled}" PlaceholderColor="Black">
                <Entry.FontFamily>
                  <OnPlatform x:TypeArguments="x:String"
                         iOS="avenir"
                                   Android="Fonts/AvenirLTStd-Book.ttf#AvenirLTStd-Book"/>
                </Entry.FontFamily>
              </Entry>

                                <Button Grid.Row="1" Grid.Column="1" Clicked="populateclaim1" BackgroundColor="Transparent" IsEnabled="{Binding enabled}"/>
                                <Label Text="Payment Type" TextColor="Gray" FontSize="14" FontFamily="avenir" Grid.Row="2" Grid.Column="0">
                <Label.FontFamily>
                  <OnPlatform x:TypeArguments="x:String"
                           iOS="avenir"
                                   Android="Fonts/AvenirLTStd-Book.ttf#AvenirLTStd-Book"/>
                </Label.FontFamily>
              </Label>

                                <local:BindablePicker  ItemsSource="{Binding Cats}" SelectedItem="{Binding SelectedCat}" Grid.Row="2" Grid.Column="0"></local:BindablePicker>
                                <Entry Text="{Binding paymenttype}" Placeholder="{Binding ddlvalue1}" FontSize="14" Grid.Row="3" Grid.Column="0" IsEnabled="{Binding enabled}" PlaceholderColor="Black">
                <Entry.FontFamily>
                  <OnPlatform x:TypeArguments="x:String"
                         iOS="avenir"
                                   Android="Fonts/AvenirLTStd-Book.ttf#AvenirLTStd-Book"/>
                </Entry.FontFamily>
              </Entry>
                                <Button Grid.Row="3" Grid.Column="0" Clicked="populateclaim" BackgroundColor="Transparent" IsEnabled="{Binding enabled}"/>


              <Label Text="Driver Name" TextColor="Gray"  FontSize="14" FontFamily="avenir" Grid.Row="2" Grid.Column="1">
                <Label.FontFamily>
                  <OnPlatform x:TypeArguments="x:String"
                           iOS="avenir"
                                   Android="Fonts/AvenirLTStd-Book.ttf#AvenirLTStd-Book"/>
                </Label.FontFamily>
              </Label>
              <Entry Completed="drivername" IsEnabled="{Binding enabled}" Text="{Binding drivername}" PlaceholderColor="Gray" FontSize="14" FontFamily="avenir" Grid.Row="3" Grid.Column="1">
                <Entry.FontFamily>
                  <OnPlatform x:TypeArguments="x:String"
                           iOS="avenir"
                                   Android="Fonts/AvenirLTStd-Book.ttf#AvenirLTStd-Book"/>
                </Entry.FontFamily>
              </Entry>

                                <Label Text="Scanned Document" TextColor="Gray" IsVisible="False" FontSize="14" FontFamily="avenir" Grid.Row="4" Grid.Column="0">
                <Label.FontFamily>
                  <OnPlatform x:TypeArguments="x:String"
                           iOS="avenir"
                                   Android="Fonts/AvenirLTStd-Book.ttf#AvenirLTStd-Book"/>
                </Label.FontFamily>
              </Label>
                                <local:ButtonUploadClick Text="Choose" IsVisible="False" FontSize="14" FontFamily="avenir" Grid.Row="5" Grid.Column="0" BackgroundColor="Transparent"/>



              <Label Text="Claim Amount" TextColor="Gray"  FontSize="14" FontFamily="avenir" Grid.Row="4" Grid.Column="1">
                <Label.FontFamily>
                  <OnPlatform x:TypeArguments="x:String"
                           iOS="avenir"
                                   Android="Fonts/AvenirLTStd-Book.ttf#AvenirLTStd-Book"/>
                </Label.FontFamily>
              </Label>
              <Entry Completed="claimamount" IsEnabled="{Binding enabled}" Text="{Binding amount}" Grid.Row="5" Grid.Column="1" PlaceholderColor="Gray" FontSize="14" FontFamily="avenir">
                <Entry.FontFamily>
                  <OnPlatform x:TypeArguments="x:String"
                           iOS="avenir"
                                   Android="Fonts/AvenirLTStd-Book.ttf#AvenirLTStd-Book"/>
                </Entry.FontFamily>
              </Entry>
                                <Button x:Name="delete" Text="Delete" ClassId="{Binding btn_tag}" BackgroundColor="Transparent"  Grid.Row="6"
     Grid.Column="0" Clicked="DeleteSeletecItem" IsVisible="True" HorizontalOptions="CenterAndExpand"></Button>







                            </Grid>

          </StackLayout>


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

  </ListView>

Upvotes: 0

Views: 1223

Answers (2)

Stephane Delcroix
Stephane Delcroix

Reputation: 16232

Since 2.3.4, Xamarin.Forms Picker is Bindable. You can bind the ItemsSource in your DataTemplate just like you Bind every other value in there.

Upvotes: 2

Renjith
Renjith

Reputation: 682

I couldn't get you. Are you saying that you are getting the picker pop on clicking and values are not shown in the pop up? If this is the case try to declare the Cats as ObservableCollection

Upvotes: 0

Related Questions