除了使用BindingContext
以外,绑定所选项的属性的另一种方法是什么?
ListView:以下是我选择列表项目的方法:
async void OnListItemSelected(object sender, SelectedItemChangedEventArgs e)
{
((App)App.Current).ResumeAtDatabaseId = (e.SelectedItem as DatabaseItem).ID;
Debug.WriteLine("setting ResumeAtDatabaseId = " + (e.SelectedItem as DatabaseItem).ID);
await Navigation.PushAsync(new DatabaseItemView
{
BindingContext = e.SelectedItem as DatabaseItem
});
}
ItemView:现在显示正在使用SetBinding
来绑定两个视图之间的数据。
public DatabaseItemView ()
{
//InitializeComponent ();
//Name
Name = new Entry
{
Placeholder = "Name"
};
Name.SetBinding(Entry.TextProperty, "Name");
//Date
Date = new DatePicker
{
Date = DateTime.Now.Date
};
Date.SetBinding(DatePicker.DateProperty, "Date");
...
目前正在运作。我想更多地控制这个绑定和数据值设置。