为了保持一致性,就像在Touch中一样,我们在LoadView中创建布局(来自笔尖或代码),并在ViewDidLoad中设置所有绑定:我想我会在Droid中做类似的事情。所以,我会在OnCreate上创建和SetContentView,然后在OnViewModelSet上设置绑定。
这让我误以为
03-29 22:13:13.892 I / mono-stdout(2447):MvxBind:警告:9.53无法为绑定创建目标绑定Click for CallCustomerServiceCommand
如果我将绑定代码移动到OnCreate中,它可以正常工作。 如果我在OnViewModelSet中移动SetContentView,它可以正常工作。
我可以在一个地方设置所有内容,但这是默认行为吗?
只有一个文本区域和两个按钮的示例视图;所有文字都要来了
public class TopupErrorView : BaseView
{
#region Controls
private MyLabel PageText;
private MyButton ButtonCallCustomerService;
private MyButton ButtonCallPayByPhone;
#endregion
#region Setup View
protected override LinearLayout MainContent(out LinearLayout footer)
{
footer = null;
var content = new StackPanel(this, Orientation.Vertical)
{
Spacing = 10,
SubViews = new View[]
{
PageText = new MyLabel(this, "PageText"),
ButtonCallCustomerService = new MyButton(this, "ButtonCallCustomerService"),
ButtonCallPayByPhone = new MyButton(this, "ButtonCallPayByPhone")
}
};
return content;
}
public new TopupErrorViewModel ViewModel
{
get { return (TopupErrorViewModel)base.ViewModel; }
}
#endregion
#region All Binding
protected override void SetupBinding()
{
#region Common Section between Platforms
var set = this.CreateBindingSet<TopupErrorView, TopupErrorViewModel>();
set.Bind(PageText).To(vm => vm.PageText).OneTime();
set.Bind(ButtonCallCustomerService).For(c => c.Content).To(vm => vm.ButtonTextCustomerService).OneTime();
set.Bind(ButtonCallCustomerService).To(vm => vm.CallCustomerServiceCommand).OneTime();
set.Bind(ButtonCallPayByPhone).For(c => c.Content).To(vm => vm.ButtonTextPayByPhone).OneTime();
set.Bind(ButtonCallPayByPhone).To(vm => vm.CallPayByPhoneCommand).OneTime();
set.Apply();
#endregion
}
#endregion
}
基类:
public abstract class BaseView : MvxActivity
{
private MasterPageControl _masterPageControl;
#region Abstract
protected abstract LinearLayout MainContent(out LinearLayout footer);
protected abstract void SetupBinding();
#endregion
#region Handling page events
protected sealed override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
}
protected sealed override void OnViewModelSet()
{
_masterPageControl = new MasterPageControl(this);
LinearLayout footer;
var contentLayout = MainContent(out footer);
var layout = _masterPageControl.GetLayout(contentLayout, footer);
SetContentView(layout);
SetupBinding();
}
#endregion
}
理想情况下,我希望OnViewModelSet只有行SetupBinding()
答案 0 :(得分:1)
我以为我会在Droid中做类似的事情。所以,我会在OnCreate上创建和SetContentView
我怀疑这里的问题是在OnViewModelSet
期间调用base.OnCreate(bundle)
- 所以&#39;跟随&#39;您正在寻找的序列不会发生 - 尽管如果没有看到2种方法的代码,很难确定。
OnViewModelSet
本身只是mvx v1中的一个残余 - 它不是MvvmCross中的关键方法。我见过的大多数示例都直接在OnCreate
中工作,这与在iOS中ViewDidLoad
工作非常类似。