我想将map与一个字段及其click事件绑定在一起,这将把它带到一个MvxCommand并显示一些MapViewModel。
[Register("HoursEntryCell")]
public class HoursEntryCell : MvxTableViewCell
{
public HoursEntryCell()
{
CreateLayout();
InitializeBindings();
}
public HoursEntryCell(IntPtr handle)
: base(handle)
{
CreateLayout();
InitializeBindings();
}
private UILabel hours;
private UIImageView imageView;
private UILabel jobName;
private MKMapView location;
private void CreateLayout()
{
jobName = new UILabel(new RectangleF(10, 10, 100, 30));
jobName.AdjustsFontSizeToFitWidth = true;
jobName.Lines = 0;
jobName.Font = jobName.Font.WithSize(16);
imageView = new UIImageView(UIImage.FromBundle("pencil.png"));
imageView.Frame = new RectangleF(270, 10,imageView.Image.CGImage.Width, imageView.Image.CGImage.Height);
Accessory = UITableViewCellAccessory.DisclosureIndicator;
location = new MKMapView(new RectangleF(15, 40, 280, 160));
location.AddAnnotation(new MKPointAnnotation()
{
Title = "My Loc",
Coordinate = new CLLocationCoordinate2D(23.0092509, 72.5061084)
});
location.UserInteractionEnabled = false;
salaryLable.Text = "Salary";
hours = new UILabel(new RectangleF(200,200,50,50));
ContentView.AddSubviews(jobName, location, hours,salaryLable, imageView);
}
private void InitializeBindings()
{
this.DelayBind(() =>
{
var set = this.CreateBindingSet<HoursEntryCell, ListViewModel>();
set.Bind(location).To(vm => vm.MyLocation);
set.Bind(hours).To(vm => vm.Salary);
set.Bind(jobName).To(vm => vm.EmployeeName);
set.Apply();
});
}
}
}
我想实现像set.Bind(location).To(vm =&gt; vm.GoNextCommand);和地图一起(set.Bind(location).To(vm =&gt; vm.MyLocation);)
或者如何从列表中将简单图像按钮单击事件绑定到MvxCommand?
我该怎么做? 需要帮助。
答案 0 :(得分:1)
你可能需要做一些事情的组合才能让它正常运作......
1。)从包含列表视图的视图中进行绑定。在上面的示例中,单元格如何实际访问您的视图模型?请看这里的示例:https://github.com/MvvmCross/MvvmCross-Tutorials/blob/master/DailyDilbert/DailyDilbert.Touch/Views/ListView.cs#L16
2。)你可能需要创建自定义绑定来处理地图视图,或者它可能类似于Stuart的这个例子:MvvmCross iOS: How to bind MapView Annotation to jump to another view?