Xamarin和Xamarin.Forms的新作。
我在EntryCell.ClearValue(BindableProperty p)上找不到任何文档
当用户进入第一个 EntryCell时,我想清除第二个 EntryCell
firstcellEntryCell.Tapped += (sender, e) => secondEntryCell.ClearValue(EntryCell.TextProperty);
这是否有意义,或者这不是EntryCell.ClearValue的预期用途?
答案 0 :(得分:2)
为了简单起见,我使用了Xamarin Forms文档中的tableview示例:
namespace EntryCellTest
{
public class EntryCellTestView : ContentPage
{
public EntryCellTestView ()
{
this.BindingContext = new EntryCellTestViewModel ();
Label header = new Label {
Text = "EntryCell",
Font = Font.BoldSystemFontOfSize (50),
HorizontalOptions = LayoutOptions.Center
};
var entryCell1 = new EntryCell {
Label = "EntryCell1:",
Placeholder = "Type Text Here"
};
entryCell1.SetBinding(EntryCell.TextProperty, new Binding("EntryText1", BindingMode.TwoWay));
var entryCell2 = new EntryCell {
Placeholder = "Type Text Here"
};
// entryCell2.SetBinding (EntryCell.TextProperty, "EntryText2",BindingMode.TwoWay);
entryCell2.SetBinding(EntryCell.TextProperty, new Binding("EntryText2", BindingMode.TwoWay));
entryCell2.SetBinding (EntryCell.LabelProperty, "EntryTextLabelProperty");
TableView tableView = new TableView {
Intent = TableIntent.Form,
Root = new TableRoot {
new TableSection {
entryCell1,
entryCell2
}
}
};
// Accomodate iPhone status bar.
this.Padding = new Thickness (10, Device.OnPlatform (20, 0, 0), 10, 5);
// Build the page.
this.Content = new StackLayout {
Children = {
header,
tableView
}
};
}
}
public class EntryCellTestViewModel : INotifyPropertyChanged
{
public EntryCellTestViewModel ()
{
this.EntryTextLabelProperty = "Just a test";
}
private string entryTextLabelProperty;
public string EntryTextLabelProperty {
get {
return entryTextLabelProperty;
}
set {
entryTextLabelProperty = value;
OnPropertyChanged ("EntryTextLabelProperty");
}
}
private string entryText1;
public string EntryText1 {
get {
return entryText1;
}
set {
entryText1 = value;
OnPropertyChanged ("EntryText1");
}
}
private string entryText2;
public string EntryText2 {
get {
return entryText2;
}
set {
entryText2 = value;
this.EntryText1 = "";
OnPropertyChanged ("EntryText2");
}
}
#region INotifyPropertyChanged implementation
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged ([CallerMemberName]string propertyName = null)
{
if (PropertyChanged != null) {
PropertyChanged (this, new PropertyChangedEventArgs (propertyName));
}
}
#endregion
}
}
显然,您可以更改绑定和设置逻辑以获得所需的结果。