原始问题:
尝试使用MVVM Light将我的viewmodel中的值绑定到Xamarin Android中的TextView时遇到问题.值会更改一次然后停止工作.即使对象在viewmodel中更改并且绑定模式设置为默认值(OneWay).
由于业务需求,我需要继续使用MVVM Light和Xamarin Android.
例:
在我的第一个片段中,我有一个书籍列表,这些书籍被绑定到我的viewmodel中的书籍列表.在我的viewmodel中,我有一个名为CurrentBook的对象,它随着我列表中的onclick事件而变化.
VM.CurrentBook = Books[index];
在我的第二个片段中,我将标题绑定到TextView
_titleBinding = this.SetBinding(() => VM.CurrentBook.Title,() => TitleTextView.Text);
当前书籍第一次从NULL更改为Book实例时,标题会根据需要更改.第一次更改VM.CurrentBook = Books [index]后;标题与第一本选集书保持一致.
更新:
我在Milen Pavlov的帮助下尝试过几件事,
我试过换到
VM.SetBinding(() => VM.CurrentBook.Title,TitleTextView,() => TitleTextView.Text,BindingMode.TwoWay);
这会触发错误:
System.Reflection.TargetException: Object of type '[Solution].Client.Shared.viewmodels.Booksviewmodel' doesn't match target type '[Solution].Client.Android.BookDetailsFragment'
我试过的另一件事:
_titleBinding = this.SetBinding(() => VM.CurrentBook.Title,BindingMode.TwoWay); enter code here
System.Reflection.TargetException: Object of type 'Android.Support.V7.Widget.AppCompatTextView' doesn't match target type '[solution].Client.Android.BookDetailsFragment'
解决方法
当xamarin android和mvvm-light上的数据绑定时,我一直在使用这个重载:
VM.SetBinding(() => VM.CurrentBook.Title,BindingMode.TwoWay);
希望能帮助到你.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。