我正在使用Cheesebaron的MvxViewPagerFragmentAdapter示例的实现,可以在此处找到http://blog.ostebaronen.dk/2013/07/fragments-and-viewpager-with-mvx.html
var fragments = new List<MvxViewPagerFragmentAdapter.FragmentInfo>
{
new MvxViewPagerFragmentAdapter.FragmentInfo
{
FragmentType = typeof(JobDetailsView),
Title = "Detail",
ViewModel = ViewModel
},
new MvxViewPagerFragmentAdapter.FragmentInfo
{
FragmentType = typeof(JobFeaturesView),
Title = "Info",
ViewModel = ViewModel
}
}
在我的JobDetailsView的OnCreateView中,我可以使用BindingInflate扩展我指定的布局,并且我在XML布局中指定的任何绑定都能正常工作。
我现在需要以编程方式绑定某些元素,我尝试使用CreateBindingSet进行绑定,但绑定不起作用。我尝试过一个简单的文本属性和一个按钮点击。当在XML中指定时,这两个都可以工作。
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Android.OS.Bundle savedInstanceState)
{
var ignored = base.OnCreateView(inflater, container, savedInstanceState);
this.EnsureBindingContextIsSet(savedInstanceState);
_view = this.BindingInflate(Resource.Layout.jobview_details, null);//jobview_withtabs_details
var signatureCard = _view.FindViewById<CardFeature>(Resource.Id.signature_cardview);
signatureCard.FindViewById<TextView>(Resource.Id.tv_basecard_header_title).Text = "Signature";
var signatureButton = signatureCard.FindViewById<Button>(Resource.Id.btn_basecard_footer).Text = "Capture";
var set = this.CreateBindingSet<JobDetailsView, JobWithTabsViewModel>();
set.Bind(signatureButton).To(vm => vm.SignatureClickCommand);
set.Apply();
return _view;
}
在我的输出窗口中,我可以看到这一点,但我不知道该怎么做才能解决它:
04-16 17:40:43.721 I/mono-stdout(27727): MvxBind:Error: 23.79 Empty binding target passed to MvxTargetBindingFactoryRegistry
MvxBind:Warning: 23.80 Failed to create target binding for binding for SignatureClickCommand
[0:] MvxBind:Warning: 23.80 Failed to create target binding for binding for SignatureClickCommand
04-16 17:40:43.731 I/mono-stdout(27727): MvxBind:Warning: 23.80 Failed to create target binding for binding for SignatureClickCommand
有人有什么想法吗?
更新
以典型的方式,离开它一小时,意识到我的错误。
键入以下内容我很懒:
var signatureButton = signatureCard.FindViewById<Button>(Resource.Id.btn_basecard_footer).Text = "Capture"
令人困惑的是绑定。切换到:
var signatureButton = signatureCard.FindViewById<Button>(Resource.Id.btn_basecard_footer);
signatureButton.Text = "Capture";
它完美无缺
答案 0 :(得分:0)
使用TabView和ViewPager的更新示例可在此处获取:https://github.com/MvvmCross/MvvmCross-AndroidSupport/tree/master/Samples
它使用Android设计库中的最新内容。