【问题标题】:Xamarin.Forms Get the object of a ListView when an Entry in the ListView is changedXamarin.Forms 当ListView中的Entry发生变化时获取ListView的对象
【发布时间】:2017-02-05 22:52:34
【问题描述】:

我有一个项目类,其中包含存储在 SQLite 数据库中的名称和价格值。我在 Listview 中显示它们,其中名称为 Label,价格为 Entry。

<ListView x:Name="itemListView">
  <DataTemplate>
    <ViewCell>
      <StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand">
        <Label Text="{Binding name}"/>
        <Entry Text="{Binding Path=price, Mode=TwoWay, StringFormat='{}{0:c}'}" Keyboard="Numeric" Completed="updateItem" />
      </StackLayout>
    </ViewCell>
  </DataTemplate>
</ListView>

我想这样当条目更改完成时,它将使用新的价格值更新 SQLite 数据库中的项目,但是,我不知道如何从 Listview 中检索已完成的项目。我想我需要使用下面的方法,但我不知道该放什么。

async void updateItem(object sender, EventArgs e)
{
    //Code to update the item with the SQLite database with the new price
}

【问题讨论】:

    标签: c# xaml xamarin.forms xamarin.forms.listview


    【解决方案1】:

    在您的 updateItem 处理程序中,项目的 BindingContext 应该是正在更新的 ItemSource 中的元素

    async void updateItem(object sender, EventArgs e)
    {
        var item = (MyItemType) ((Entry)sender).BindingContext;
    
        //Code to update the item with the SQLite database with the new price
    }
    

    【讨论】:

      猜你喜欢
      • 2015-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多