我已經實施了綁定到ObservableCollection
的ListView
,並且我需要在輸入字段更改時更新每個項目。我正在使用已完成的事件,但它只會將輸入值傳遞給已完成的事件函數,並且我不知道我正在編輯哪個對象。如何將對象參數傳遞給Xamarin.Forms中的Entry事件?
是否有任何方法可以將對象參數傳遞給這些入口事件,以便我可以更新正確的對象?還是有更好的方法來做到這一點?
UPDATE
這是這是綁定到一個可觀察的集合,是在我的ViewModel我的列表視圖代碼
<ListView
x:Name="DrawReturnList"
RowHeight="65"
BackgroundColor="#ffffff"
CachingStrategy="RecycleElement"
ItemsSource="{Binding SCSDraw}"
ItemSelected = "OnItemTapped"
IsPullToRefreshEnabled="false"
Margin="0, -10, 0, 0">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"
Orientation="Vertical"
Padding="10">
<StackLayout Orientation="Horizontal">
<StackLayout HorizontalOptions="FillAndExpand" WidthRequest="90" Padding="0, 10, 0, 0">
<Label Text="{Binding PubDateShort3}" FontSize="18"/>
</StackLayout>
<StackLayout HorizontalOptions="FillAndExpand" Orientation="Horizontal">
<Grid HorizontalOptions="FillAndExpand" ColumnSpacing="0" RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackLayout Grid.Row="0" Grid.Column="0" Padding="0, 10, 0, 0">
<Label Text="{Binding InitialDraw}" FontSize="18"/>
</StackLayout>
<StackLayout Grid.Row="0" Grid.Column="1">
<Entry IsEnabled="{Binding ACLockFL, Converter={StaticResource not}}" Keyboard="Numeric" Placeholder="Draw" Text="{Binding Draw, Mode=TwoWay}" VerticalOptions="Center"/>
</StackLayout> <!-- end Draw -->
<StackLayout Grid.Row="0" Grid.Column="2">
<Entry IsEnabled="{Binding ACLockFL, Converter={StaticResource not}}" Keyboard="Numeric" Placeholder="Returns" Text="{Binding Returns, Mode=TwoWay}" VerticalOptions="Center"/>
</StackLayout> <!-- end Return -->
</Grid>
</StackLayout>
</StackLayout><!-- end input group -->
</StackLayout> <!-- end Draw & Return Section-->
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView> <!-- end list view -->
。
我需要做的是能夠編輯每個單獨的列表項目與其各自的條目,並將其保存到其各自的對象。我嘗試了Entry上的完成事件,但是我無法傳遞參數。我應該如何處理這個問題?
UPDATE
模型
using System;
using System.ComponentModel;
using Collector.Helpers;
namespace Collector
{
public class AC_SCSDraw : EntityData, INotifyPropertyChanged
{
private int draw;
private int returns;
public decimal CarrierID { get; set; }
public decimal RspID { get; set; }
public string RspName { get; set; }
public decimal SCSDrawID { get; set; }
public decimal PubID { get; set; }
public string PubDesc { get; set; }
public string WeekDay { get; set; }
public DateTime PubDate { get; set; }
public string PubDateShort3 { get; set; }
public int Draw
{
get { return draw; }
set
{
draw = value;
OnPropertyChange("Draw");
}
}
public int Returns
{
get { return returns; }
set
{
returns = value;
OnPropertyChange("Returns");
}
}
public int InitialDraw { get; set; }
public bool ACLockFL { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChange(string name)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
}
視圖模型
ObservableCollection<AC_SCSDraw> scsDraw = new ObservableCollection<AC_SCSDraw>();
public ObservableCollection<AC_SCSDraw> SCSDraw
{
get { return scsDraw; }
set
{
scsDraw = value;
OnPropertyChanged("SCSDraw");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
var changed = PropertyChanged;
if (changed != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
請添加一段代碼,以便我們看到您至少嘗試了什麼。否則它幾乎是不可能的幫助 – Joehl
@Joehl請參閱上面的更新。謝謝 –