2017-02-05 3 views
0

SQLiteデータベースに格納されている名前と価格の値を持つアイテムクラスがあります。私はListviewに名前のラベルと価格のエントリを表示しています。Xamarin.Forms ListViewのエントリが変更されたときにListViewのオブジェクトを取得します。

<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データベース内の項目を更新するようにしたい、私は完成したアイテムを取得する方法がわかりませんリストビューから。私は次の方法を使う必要があると思うが、何を入れるべきか分からない。あなたのupdateItemハンドラで

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

答えて

0

、その項目のBindingContextを働いた

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 
} 
+0

を更新されているItemSourceからの要素でなければなりません。ありがとうございました! – cvanbeek

関連する問題