【问题标题】:Xamarin Forms ListView Data BindingXamarin 表单 ListView 数据绑定
【发布时间】:2016-09-08 18:40:15
【问题描述】:

xaml.cs 代码中的ObservableCollection<string> CompanyList 与 xaml 中的<ListView> 元素相关联。不理会它,它按预期显示CompanyList 中的字符串列表。

但是,我想自定义(纯粹出于样式目的)ListView 中的ViewCell,同时将CompanyList 保留为strings 的集合。我不确定如何绑定string 公司列表值。

    <ListView x:Name="CompanyList" ItemTapped="OnAddCompanyFilterTapped" >
      <ListView.ItemTemplate>
        <DataTemplate>
          <ViewCell>
            <StackLayout Padding="0" Spacing="0">
              <StackLayout  Padding="10">
                <Label Text="{Binding ??????????}" HorizontalOptions="Fill"/>
              </StackLayout>                  
              <BoxView Style="{StaticResource divider}"/>
            </StackLayout>                
          </ViewCell>
        </DataTemplate>
      </ListView.ItemTemplate>
    </ListView>

我在里面放什么??????让CompanyList中的字符串显示?

非常感谢任何帮助/建议/想法!

【问题讨论】:

    标签: xaml listview data-binding xamarin xamarin.forms


    【解决方案1】:

    Binding Path=.应该可以,可以缩短:

    <Label Text="{Binding}" HorizontalOptions="Fill"/>
    

    假设ListView.ItemsSource 仍然是CompanyList

    【讨论】:

    • 谢谢!大声笑在此停留了一段时间,因为我没有绑定它的属性>
    猜你喜欢
    • 1970-01-01
    • 2016-10-10
    • 1970-01-01
    • 1970-01-01
    • 2018-10-19
    • 2018-08-14
    • 2018-09-25
    • 1970-01-01
    • 2021-10-20
    相关资源
    最近更新 更多