Ale*_* D. 6 binding button xamarin.android mvvmcross
当我尝试使用MvvmCross框架将我的Android Button的"Enabled"属性绑定到我的ViewModel的布尔值时出现问题,我真的不知道它的来源.
所以我有一个ViewModel,它包含以下两个属性:
private ProjectDetailDTO _projectDetail;
public ProjectDetailDTO ProjectDetail
{
get { return this._projectDetail; }
set
{
_projectDetail = value;
RaisePropertyChanged(() => ProjectDetail);
RaisePropertyChanged(() => HasPicture);
}
}
private bool _hasPicture;
public bool HasPicture
{
get { return ((this.ProjectDetail != null) && !String.IsNullOrEmpty(this.ProjectDetail.Pictures)); }
set { _hasPicture = value;
RaisePropertyChanged(() => HasPicture);
}
}
Run Code Online (Sandbox Code Playgroud)
正如您所理解的,我的按钮绑定到HasPicture属性.所以我的.axml文件中的按钮代码如下:
<Button
local:MvxLang="Text LblSeePicturesValue"
local:MvxBind="Enabled HasPicture,Click ShowProjectPicturesCommand"
android:id="@+id/buttonPictures"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
Run Code Online (Sandbox Code Playgroud)
我不认为这是一个ViewModel问题,因为我的WP应用程序适用于此代码.事实上,我的ProjectDetailDTO是通过调用Web服务来填充的,所以通过异步方法.我认为这就是为什么在实现绑定时HasPicture属性具有false值的原因.但是使用我的ViewModel代码时,应该在填充ProjectDetailDTO时更新HasPicture属性.我的Android视图中有什么问题吗?
谢谢你的帮助 !
Stu*_*art 10
我认为你在这里看到的是ICommand.CanExecute与Enabled财产之间的一些互动.有关这方面的讨论,请访问https://github.com/MvvmCross/MvvmCross/issues/729
要解决此问题,请尝试将绑定切换为:
local:MvxBind="Click ShowProjectPicturesCommand;Enabled HasPicture"
Run Code Online (Sandbox Code Playgroud)
(另请注意,绑定中的分隔符是;- 而不是a ,)