如何将值绑定到xamarin中listview内的选择器

时间:2017-05-03 08:28:27

标签: xamarin.forms

在xamarin表单中我使用列表查看里面我需要实现选择器。因为我们无法从listview中取出id,所以我无法将值加载到选择器。有没有办法做到这一点。这是包含listview的xaml代码

      <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>

2 个答案:

答案 0 :(得分:2)

自2.3.4以来,Xamarin.Forms Picker是可绑定的。您可以绑定DataTemplate中的ItemsSource,就像绑定其中的所有其他值一样。

答案 1 :(得分:0)

我无法得到你。你是说你点击选择器弹出窗口并且弹出窗口中没有显示值?如果是这种情况,请尝试将Cats声明为ObservableCollection